Bug #27859 LongText parameter gets truncated with UTF-8 server connections

Submitted: 16 Apr 2007 19:30 Modified: 26 Apr 2007 6:18
Reporter: Luca Leonardo Scorcia Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.0.6, server 5.0.22 OS:Windows
Assigned to: CPU Architecture:Any

[16 Apr 2007 19:30] Luca Leonardo Scorcia
Description:
It seems like the connector is truncating a LongText field during an UPDATE query. The field is populated with a string, and has to be encoded by the connector in UTF-8 since that is the connection charset.

How to repeat:
Just try to insert an 'รจ' character into a longtext column with UTF-8 charset, collation utf8_general_ci, with database and server set to utf8 encoding, and utf8 connection. You'll see the reported behavior.

Suggested fix:
In MySqlBinary.cs, 
at the method void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length),
line 132, EscapeByteArray(buffToWrite, length, stream);

buffToWrite.Length is 678 while the variable length contains the value 676. 

This is because after line 111, buffToWrite = stream.Encoding.GetBytes(s);
buffToWrite is larger than the original string due to multi-byte encoding in UTF-8, but the call to EscapeByteArray uses the old length.

Suggested fix is simply to assign after line 111 the correct buffer length:

length = buffToWrite.Length;

From a quick check, it seems to work.

Please, can you provide a reasonable time frame for an official fix? I wouldn't like to install a homebrew assembly on the production server...
[25 Apr 2007 18:37] Luca Leonardo Scorcia
Nevermind, it was my fault.
The DB table was correctly set to LongText, but I was passing in the wrong kind of parameter (MySqlDbType.LongBlob), thus things got a bit messed up. I did a couple of tests with both the correct pairs (BLOB / MySqlDbType.Blob and Text / MySqlDbType.Text) and everything worked. Thank you for your time.
[26 Apr 2007 6:18] Tonci Grgin
Luca, thanks for your report and sorry for the delay. I'm glad you managed to find the problem.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.058 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.