Bug #16929 Long values cannot be read from wire
Submitted: 31 Jan 2006 10:39 Modified: 22 May 2006 20:47
Reporter: Thomas Krüger Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.7 OS:Windows (Windows XP Professional)
Assigned to: CPU Architecture:Any

[31 Jan 2006 10:39] Thomas Krüger
Description:
When reading long (int64 or uint64) values from the wire, the PacketReader.ReadLong method does not produce the correct values.
Also, the method is not implemented performant and is also used to read int32 values.

How to repeat:
This is visible when a value > 2^32 or value < -2^32 is to be read as the 'raise' variable will overflow.

Suggested fix:
		// First byte is least-significant, last byte most significant.
		public ulong ReadLong( int numbytes ) 

		{

			ulong val = 0;
			int raise = 0;
			for (int x=0; x < numbytes; x++)
			{
				ulong b = (ulong)ReadByte();
				val   += (b<<raise);
				raise += 8;
			}
			return val;
		}
[7 Apr 2006 19:55] Tonci Grgin
Hi.  Thanks for your problem report. I was unable to repeat it so could you provide me with your application and sample data that shows it?
[26 Apr 2006 7:41] Tonci Grgin
Hi. Thanks for your test case. I was able to repeat the error as reported with latest build of connector/NET and test case provided.

Server version: 5.1.7-beta-nt-max-log
Inserting id=45, sval=-9000000000000000000, uval=18446725308424768716
Rows=1
[0] id=45 sval=494665728 uval=18446744073136884940
[1] id=45 sval=494665728 uval=18446744073136884940
[22 May 2006 20:47] Reggie Burnett
This was a duplicate of bug #16934. 

I am not using the Converter class since that would require a memory allocation every time through.  Also, it is not obvious that a switch statement would be significantly faster although I have made a note to check this out.

Thanks for your bug report.