[Mono-bugs] [Bug 350860] New: System.IO. MemoryStream ToArray fails if Capacity is set to 0

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Dec 27 19:04:07 EST 2007


           Summary: System.IO.MemoryStream ToArray fails if Capacity is set
                    to 0
           Product: Mono: Class Libraries
           Version: 1.2.6
          Platform: x86
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: casey.s.marshall at gmail.com
         QAContact: mono-bugs at ximian.com
          Found By: ---

Created an attachment (id=188834)
 --> (https://bugzilla.novell.com/attachment.cgi?id=188834)
Test case.

If you use a MemoryStream, then set the Length to 0 and the Capacity to 0
(creating an empty MemoryStream) the ToArray method will fail.

Steps to reproduce:

1. run the attached test case.

Expected results: three lines are printed: one blank, one saying 'atoms:', one

Actual results: the program crashes with this output:

-> atoms:
-> Stacktrace:
->   at (wrapper managed-to-native) System.Buffer.BlockCopyInternal
(System.Array,int,System.Array,int,int) <0x00004>
->   at (wrapper managed-to-native) System.Buffer.BlockCopyInternal
(System.Array,int,System.Array,int,int) <0xffffffff>
->   at System.IO.MemoryStream.ToArray () <0x00042>
->   at zeroms.Main () <0x00185>
->   at (wrapper runtime-invoke) zeroms.runtime_invoke_void
(object,intptr,intptr,intptr) <0xffffffff>
-> Abort trap

Looking at the code to MemoryStream, it looks like the Capacity setter sets
'internalBuffer' to null when the capacity is zero, but that there isn't
anything handling a null 'internalBuffer' properly in ToArray. That is, a null
array is passed to Buffer.BlockCopyInternal.

Also reproduces on mono 1.2.4 on GNU/Linux x86 (Ubuntu gutsy mono package).

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

More information about the mono-bugs mailing list