db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kristian Waagan (JIRA)" <j...@apache.org>
Subject [jira] Updated: (DERBY-4060) Blob.getBinaryStream(long,long) is off by one for the pos+len check
Date Thu, 26 Feb 2009 11:45:01 GMT

     [ https://issues.apache.org/jira/browse/DERBY-4060?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Kristian Waagan updated DERBY-4060:

    Attachment: derby-4060-1a-sub_stream_fix.stat

The patch 'derby-4060-1a-sub_stream_fix.diff' fixes the reported bug.
The changes in the production code consist of subtracting one from the position when checking
against the length.
Using the example from the report;
 o current: 11 + 10 > 20 = true (exception thrown)
 o with patch: (11 -1) + 10 > 20 = false (check passes)

I made some more changes to the test code. Three tests were added, one for Blob and two for
Clob (one Clob loaded with latin chars only, one loaded with CJK chars).
In addition, CharAlphabet-objects cannot be shared between readers. I dealt with this by adding
getClone method to the CharAlphabet-class, and getting a clone when creating the LoopingAlphabetReader.
This should maybe be changed in a more robust way.
It should also be noted that the method draining the stream and returning the last byte/char,
performs more checks than usual.

Patch ready for review.

> Blob.getBinaryStream(long,long) is off by one for the pos+len check
> -------------------------------------------------------------------
>                 Key: DERBY-4060
>                 URL: https://issues.apache.org/jira/browse/DERBY-4060
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC, Network Client
>    Affects Versions:,
>            Reporter: Trejkaz
>            Assignee: Kristian Waagan
>         Attachments: derby-4060-1a-sub_stream_fix.diff, derby-4060-1a-sub_stream_fix.stat
> If you have a BLOB of length 20, and call blob.getBinaryStream(11,10), it will give you
an error:
>     java.sql.SQLException: Sum of position('11') and length('10') is greater than the
size of the LOB.
> This is following word for word an error in the JDBC Javadoc:
>         SQLException - if pos is less than 1 or if pos is greater than the number of
bytes in the Blob or if pos + length is greater than the number of bytes in the Blob
> So it's checking 11 + 10 > 20, but it should check 11 + 10 > 21    (pos + len >
blob.length() + 1) to allow reading the last byte.
> The Javadoc for Clob.getCharacterStream(long,long) has similar wording so it may have
the same issue.
> Likewise, the client driver may have the same issue -- I haven't yet checked.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message