List:Commits« Previous MessageNext Message »
From:vvaintroub Date:May 15 2009 3:06pm
Subject:Connector/NET commit: r1605 - in branches/5.1: . Driver/Source
View as plain text  
Modified:
   branches/5.1/CHANGES
   branches/5.1/Driver/Source/CompressedStream.cs
Log:


Modified: branches/5.1/CHANGES
===================================================================
--- branches/5.1/CHANGES	2009-05-15 14:15:29 UTC (rev 1604)
+++ branches/5.1/CHANGES	2009-05-15 15:06:28 UTC (rev 1605)
@@ -15,6 +15,8 @@
     still attempt to close the file which would yield a null reference exception (bug #43332)      
   - fixed index and index column schema collections that would fail if you specified the
     any restrictions more specific than table name (bug #43991)
+  - fixed potential endless loop in CompressedStream in case where end of stream occurs before 
+    packet is fully read (bug #43678)
   
 Version 5.1.7 - 8/20/08
  - Fixed problem with DDEX provider that could sometimes prevent table altering when working with

Modified: branches/5.1/Driver/Source/CompressedStream.cs
===================================================================
--- branches/5.1/Driver/Source/CompressedStream.cs	2009-05-15 14:15:29 UTC (rev 1604)
+++ branches/5.1/Driver/Source/CompressedStream.cs	2009-05-15 15:06:28 UTC (rev 1605)
@@ -36,6 +36,7 @@
         // reading fields
         private byte[] localByte;
         private byte[] inBuffer;
+        private byte[] lengthBytes;
         private WeakReference inBufferRef;
         private int inPos;
         private int maxInPos;
@@ -45,6 +46,7 @@
         {
             this.baseStream = baseStream;
             localByte = new byte[1];
+            lengthBytes = new byte[7];
 			cache = new MemoryStream();
             inBufferRef = new WeakReference(inBuffer, false);
         }
@@ -93,8 +95,15 @@
 
         public override int ReadByte()
         {
-            Read(localByte, 0, 1);
-            return localByte[0];
+            try
+            {
+                Read(localByte, 0, 1);
+                return localByte[0];
+            }
+            catch (EndOfStreamException)
+            {
+                return -1;
+            }
         }
 
         public override int Read(byte[] buffer, int offset, int count)
@@ -131,15 +140,12 @@
         private void PrepareNextPacket()
         {
             // read off the uncompressed and compressed lengths
-            byte b1 = (byte) baseStream.ReadByte();
-            byte b2 = (byte) baseStream.ReadByte();
-            byte b3 = (byte) baseStream.ReadByte();
-            int compressedLength = b1 + (b2 << 8) + (b3 << 16);
+            ReadFully(lengthBytes, 7);
+            int compressedLength = lengthBytes[0] + (lengthBytes[1] << 8) + (lengthBytes[2] << 16);
+            // lengthBytes[3] is seq
+            int unCompressedLength =lengthBytes[4] + (lengthBytes[5] << 8) +
+                                     (lengthBytes[6] << 16);
 
-            baseStream.ReadByte(); // seq
-            int unCompressedLength = baseStream.ReadByte() + (baseStream.ReadByte() << 8) +
-                                     (baseStream.ReadByte() << 16);
-
             if (unCompressedLength == 0)
             {
                 unCompressedLength = compressedLength;
@@ -162,11 +168,20 @@
             inBuffer = (byte[])inBufferRef.Target;
             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(inBuffer, numRead, numToRead);
+                int read = baseStream.Read(buffer, numRead, numToRead);
+                if (read == 0)
+                {
+                    throw new EndOfStreamException();
+                }
                 numRead += read;
                 numToRead -= read;
             }

Thread
Connector/NET commit: r1605 - in branches/5.1: . Driver/Sourcevvaintroub15 May