Bug #2670 setBytes on Blob truncates data
Submitted: 6 Feb 2004 19:05 Modified: 4 Aug 2004 16:39
Reporter: joseph dane Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.0.9 OS:darwin
Assigned to: Mark Matthews CPU Architecture:Any

[6 Feb 2004 19:05] joseph dane
Description:
if you have a Blob of a certain length, say 1000 bytes, and you use setBytes() on the blob
to set the values of a subset of the bytes (say the first 10), then the remainder of the blob is 
truncated, and you're left with a 10 byte blob.

there's nothing in the Blob spec to lead be to believe that this is correct.

How to repeat:
roughly, something like this:

   Blob b = rs.getBlob(1);  // 1000 byte blob
   byte[] bytes = new byte[10];
   ...
   b.setBytes(1, bytes, 0, 10);  // the blob is now only 10 bytes long, and the remaining 990 bytes 
are lost 
   

Suggested fix:
as noted in the current Blob source, the implementaion is pretty much "brain dead".  the correct
long term fix will depend on how the "brain transplant" is performed.

for now, I suggest removing the use of the output stream in setBytes(), and just using a 
System.arraycopy, since you've already got the whole blob in memory anyhow.
[8 Mar 2004 15:50] Mark Matthews
I have a fix prepared, pending some clarification of the JDBC standard on what to do if the index to write at is greater than the current blob length.
[4 Aug 2004 16:39] Mark Matthews
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/