#At file:///H:/connector_net/6.0/ based on revid:vvaintroub@stripped
731 Vladislav Vaintroub 2009-07-29
fixed potential infinite loop in LoadPacket(), when read from a stream returns 0. (bug#46308)
modified:
CHANGES
MySql.Data/Provider/Source/CompressedStream.cs
MySql.Data/Provider/Source/MySqlStream.cs
=== modified file 'CHANGES'
--- a/CHANGES 2009-07-28 20:32:52 +0000
+++ b/CHANGES 2009-07-29 11:06:15 +0000
@@ -3,6 +3,7 @@ Version 6.0.5
'allow batch=false' to their connection string (bug #45502)
- we are now throwing an exception when DeriveParameters is unable to successfully populate
the parameters array. This exception explains what is wrong (bug #45952)
+- fixed potential infinite loop in LoadPacket(), when read from a stream returns 0. (bug#46308)
Version 6.0.4
- fixed regression where using stored procs with datasets (bug #44460)
=== modified file 'MySql.Data/Provider/Source/CompressedStream.cs'
--- a/MySql.Data/Provider/Source/CompressedStream.cs 2009-06-18 20:01:15 +0000
+++ b/MySql.Data/Provider/Source/CompressedStream.cs 2009-07-29 11:06:15 +0000
@@ -144,7 +144,7 @@ namespace MySql.Data.MySqlClient
private void PrepareNextPacket()
{
- ReadFully(lengthBytes, 7);
+ MySqlStream.ReadFully(baseStream, lengthBytes, 0, 7);
int compressedLength = lengthBytes[0] + (lengthBytes[1] << 8) + (lengthBytes[2] << 16);
// lengthBytes[3] is seq
int unCompressedLength = lengthBytes[4] + (lengthBytes[5] << 8) +
@@ -174,23 +174,7 @@ namespace MySql.Data.MySqlClient
if (inBuffer == null || inBuffer.Length < len)
inBuffer = new byte[len];
- ReadFully(inBuffer, len);
- }
-
- private void ReadFully(byte[] buffer, int len)
- {
- int numRead = 0;
- int numToRead = len;
- while (numToRead > 0)
- {
- int read = baseStream.Read(buffer, numRead, numToRead);
- if (read == 0)
- {
- throw new EndOfStreamException();
- }
- numRead += read;
- numToRead -= read;
- }
+ MySqlStream.ReadFully(baseStream, inBuffer, 0, len);
}
private MemoryStream CompressCache()
=== modified file 'MySql.Data/Provider/Source/MySqlStream.cs'
--- a/MySql.Data/Provider/Source/MySqlStream.cs 2009-04-21 18:02:13 +0000
+++ b/MySql.Data/Provider/Source/MySqlStream.cs 2009-07-29 11:06:15 +0000
@@ -141,6 +141,31 @@ namespace MySql.Data.MySqlClient
return packet;
}
+ /// <summary>
+ /// Reads the specified number of bytes from the stream and stores them at given
+ /// offset in the buffer.
+ /// Throws EndOfStreamException if not all bytes can be read.
+ /// </summary>
+ /// <param name="stream">Stream to read from</param>
+ /// <param name="buffer"> Array to store bytes read from the stream </param>
+ /// <param name="offset">The offset in buffer at which to begin storing the data read from the current stream. </param>
+ /// <param name="count">Number of bytes to read</param>
+ internal static void ReadFully(Stream stream, byte[] buffer, int offset, int count)
+ {
+ int numRead = 0;
+ int numToRead = count;
+ while (numToRead > 0)
+ {
+ int read = stream.Read(buffer, offset + numRead, numToRead);
+ if (read == 0)
+ {
+ throw new EndOfStreamException();
+ }
+ numRead += read;
+ numToRead -= read;
+ }
+ }
+
/// <summary>
/// LoadPacket loads up and decodes the header of the incoming packet.
/// </summary>
@@ -163,17 +188,13 @@ namespace MySql.Data.MySqlClient
sequenceByte = (byte)++seqByte;
int length = (int)(b1 + (b2 << 8) + (b3 << 16));
- int leftToRead = length;
-
+
// make roo for the next block
packet.Length += length;
- while (leftToRead > 0)
- {
- int read = inStream.Read(packet.Buffer, offset, leftToRead);
- leftToRead -= read;
- offset += read;
- }
+ ReadFully(inStream, packet.Buffer, offset, length);
+ offset += length;
+
// if this block was < maxBlock then it's last one in a multipacket series
if (length < maxBlockSize) break;
}
Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20090729110615-20cv8mv3kra15tb2.bundle
| Thread |
|---|
| • bzr commit into connector-net-6.0 branch (vvaintroub:731) Bug#46308 | Vladislav Vaintroub | 29 Jul |