Bug #7547 PreparedStatement setBytes, setBinaryStream garbles binary data
Submitted: 27 Dec 2004 17:47 Modified: 5 Jan 2005 18:47
Reporter: David Smith Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.0.16 and up OS:MacOS (Mac OS X)
Assigned to: CPU Architecture:Any

[27 Dec 2004 17:47] David Smith
Description:
My long standing upload image code has started garbling image files. Inspection shows that the 
files are of identical length but after passing through my JDBC code they are getting slightly 
garbled (enough to corrupt the image). 

I verified the problem was in the dirver by process of elimination. I can use load_file to get a 
clean image file into the database, so the problem is not on the display side; I can also verify the 
image data is pristine up until it goes into the PreparedStatement.setBytes() or 
setBinaryStream() methods. I can verify this is not some aspect of the mine encoding and 
decoding process because I save out the uploaded file as an intermediate stage prior to 
streaming it into the database. Somewhere in the driver it gets corrupted. 

I am using MySQL 4.1 and Connector/J 3.0.16 and I also tried 3.1.5 gamma, seems to be the 
same. 

How to repeat:
This one is a little hard to setup in a test case, I know. If you need me to set up a demo of the 
problem for you to inspect I can do that.

Suggested fix:
Well, these methods worked correctly for years in the older driver. Something got changed which 
now garbles binary data--not totally, it is just in a few bytes in certain parts of the file (enough to 
be seen using diff -a but not enough to change the length of the data).
[27 Dec 2004 18:23] Mark Matthews
We'd need the exact contents of the file that gets garbled, as well as the character encodings that you're using.

We test prepared statements with randomized binary and other known 'problematic' inputs as part of our regular testsuites, so it sounds like this is related to either your character encoding and/or the specific data sequences in the files you are using.
[27 Dec 2004 20:35] David Smith
OK, this was NOT a bug in your stuff. Please close the bug report and accept my apologies.

I have been using your code for years and it is the best.

Dave Smith
[5 Jan 2005 18:47] Mark Matthews
Thanks for reporting back, and the accolades. Happy new year!