https://bugzilla.novell.com/show_bug.cgi?id=657388
https://bugzilla.novell.com/show_bug.cgi?id=657388#c0 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: [email protected] ReportedBy: [email protected] QAContact: [email protected] 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 error: Corrupted data ReadInternal... System.IO.Compression.DeflateStream.CheckResult(Int32 result, System.String where) 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 sections... /// <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[] buffer) { // Use this method is used to read all bytes from a stream. const int increment = 512; int offset = 0; int totalCount = 0; unchecked { while (true) { if ((offset + increment) > buffer.Length) { int newSize = buffer.Length + (increment * 10); #if !IPHONE Array.Resize<byte>(ref buffer, newSize); #else byte[] buffer2 = new byte[newSize]; Buffer.BlockCopy(buffer, 0, buffer2, 0, buffer2.Length); buffer = buffer2; #endif } int bytesRead = stream.Read(buffer, offset, increment); if (bytesRead == 0) { break; } offset += bytesRead; totalCount += bytesRead; } if (buffer.Length != totalCount) { #if !IPHONE Array.Resize<byte>(ref buffer, totalCount); #else byte[] buffer2 = new byte[totalCount]; Buffer.BlockCopy(buffer, 0, buffer2, 0, buffer2.Length); buffer = buffer2; #endif } 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. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
