[Mono-bugs] [Bug 657388] New: Array.Resize corrupts a GZipStream.Read operation

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Dec 3 07:54:23 EST 2010



           Summary: Array.Resize corrupts a GZipStream.Read operation
    Classification: Mono
           Product: MonoTouch
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Class Libraries
        AssignedTo: gnorton at novell.com
        ReportedBy: johan.otto at justenough.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us)
AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4

I have this static method that reads a buffer from a stream in chunks of 512
bytes... this code works fine on our other platforms but in MonoTouch I get the

Corrupted data ReadInternal... 
System.IO.Compression.DeflateStream.CheckResult(Int32 result, System.String

To workaround the problem I declared a #if !IPHONE and rather BlockCopy the
previous array into a new one. To test just take out these sections. I think
that this work-around is more memory intensive so it would be appreciated if
the issue is addressed in the mono code.

Reproducible: Always

Steps to Reproduce:
Use this method to populate a buffer from a GZipStream and take out the #if

/// <summary>
        /// Reads all bytes from stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="buffer">The buffer.</param>
        /// <returns>The number of bytes read.</returns>
        public static int ReadAllBytesFromStream(Stream stream, ref byte[]
            // Use this method is used to read all bytes from a stream.
            const int increment = 512;
            int offset = 0;
            int totalCount = 0;
                while (true)
                    if ((offset + increment) > buffer.Length)
                        int newSize = buffer.Length + (increment * 10);
                        Array.Resize<byte>(ref buffer, newSize);
                        byte[] buffer2 = new byte[newSize];
                        Buffer.BlockCopy(buffer, 0, buffer2, 0,
                        buffer = buffer2;
                    int bytesRead = stream.Read(buffer, offset, increment);
                    if (bytesRead == 0)
                    offset += bytesRead;
                    totalCount += bytesRead;
                if (buffer.Length != totalCount)

                    Array.Resize<byte>(ref buffer, totalCount);
                    byte[] buffer2 = new byte[totalCount];
                    Buffer.BlockCopy(buffer, 0, buffer2, 0, buffer2.Length);
                    buffer = buffer2;


                return totalCount;
Actual Results:  
Array.Resize somehow corrupts the buffer.

Expected Results:  
Error should not happen under normal circumstances.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list