Bug #3872 problem with ByteFX and blobs over 60KB
Submitted: 24 May 2004 14:04 Modified: 28 Jul 2004 3:18
Reporter: Jason Sherman Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:4.0.15 OS:Windows (Windows 2003 Server Standard)
Assigned to: Reggie Burnett CPU Architecture:Any

[24 May 2004 14:04] Jason Sherman
Description:
I am using your MySqlClient extensively and have noticed a possible bug. I am currently using your latest version (0.7.6.15073). When I do a select on a table containing a blob and try to read the value out of the column, I am receiving a System.OutOfMemoryException in bytefx.mysqlclient.dll. I only get this error when the blob is >60KB. Less than 64KB reads out just fine. When I switch to the older version (0.7.2.13867), it works just fine with no changes to the code. I hope you can help me with this. I would rather not downgrade my dll that I'm using because so many bugs were fixed. I've included some sample code and table layout.

Jason Sherman
www.SecurityAndMonitoring.com

How to repeat:
MySqlConnection conn = new MySqlConnection("server=localhost;database=updateDB;User ID=user;Password=pass"); conn.Open(); MySqlCommand comm = conn.CreateCommand(); comm.CommandText = "SELECT `Data` FROM `FileData` WHERE `ID`='11'"; ByteFX.Data.MySqlClient.MySqlDataReader reader = comm.ExecuteReader(); reader.Read(); object test = reader[0];

CREATE TABLE `filedata` (
  `ID` int(11) NOT NULL auto_increment,
  `Name` varchar(50) NOT NULL default '',
  `InternalVersion` varchar(20) default NULL,
  `Data` mediumblob NOT NULL,
  `MD5` tinyblob NOT NULL,
  `Signature` tinyblob NOT NULL,
  `ReleaseDate` bigint(20) NOT NULL default '0',
  PRIMARY KEY  (`ID`)
) TYPE=MyISAM AUTO_INCREMENT=538 ;

Suggested fix:
I have tracked it to MySqlClient\Field.cs, line 90. less than 60KB blob produces bufLength with the correct value, but blob greater than 64KB produces a bufLength approx 1.49GB.
[23 Jun 2004 13:00] [ name withheld ]
I'm running MySQL 4.1.2-alpha.
I've a blob with 537384 bytes of data. Using MySqlDataReader, ByteFX 0.76 told me the field was 621294376 bytes long.
621294376 = 40 51 08 37 (in decimal)
537384 = 40 51 08
So we see that it's juste 37 * 256 * 256 * 256 too large.
Either ByteFX reads 4bytes instead of 3, or MySQL Server should send a 0 instead of 37.
Let's go into Packet.cs. ReadLenInteger() and ReadInteger(int) are the functions that reads the data length from the server's stream. I fall into case 253 in ReadLenInteger(). Okay in fact in some mode intLen will be 3 or 4 mmm interresting!
Initially intLen is 3 but if you set the LongInts property as 'true', it change intLen as 4.
Driver.cs : the LongInts property is set as 'true' by CreatePacket(byte[]) if the MySQL server is at least 3.22.5.
I don't know the MySQL protocol, however disabled the LongInts property, and... I can read my blob! :D
Note that ByteFX succesfully detected that I'm running version 4.1.2.

So in a nutshell, blobs smaller than 64KB can be read, because ReadLenInteger() will read correctly one or two bytes (case 252) because the value of shortLen isn't affected by the LongInts property.

In case 254, in LongInts mode, it even reads 8bytes! that's 18'446'744'073'709'551'616 bytes wow!
In LongInts set as false, it's 4 bytes => 4GB max.
[25 Jun 2004 21:09] Jason Sherman
i figured as well that it was too many bytes for the size, but I don't know, and didn't have the time/patience to trudge through the c# code to find out why. :) Has there been any more progress???
[8 Jul 2004 17:09] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[13 Jul 2004 1:59] HYS HYS
So is this issue resolved in the latest build of mysql (4.1.3 Beta) ?
[13 Jul 2004 3:59] Reggie Burnett
A release of Connector/Net has not been made yet.  We are trying to get a version out this week.
[28 Jul 2004 0:47] HYS HYS
Hello Sorry for being annoying.

Is there any solution to this problem ?

And thanks for the efforts and reply
[28 Jul 2004 3:18] Reggie Burnett
This bug has been fixed and will be in the first release of Connector/Net