[Mono-bugs] [Bug 662994] New: NullReferenceException in String.memcpy2 when calling Marshal.PtrToStructure with invalid pointer

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Jan 7 08:19:36 EST 2011



           Summary: NullReferenceException in String.memcpy2 when calling
                    Marshal.PtrToStructure with invalid pointer
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.8.x
          Platform: i686
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Minor
          Priority: P5 - None
         Component: Sys.Core
        AssignedTo: jbevain at novell.com
        ReportedBy: zaripov.rinat at gmail.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/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10

The exception was reproduced in 2.8.1 and 2.8.2.

Here is the exception and it's call stack:

 System.NullReferenceException: Object reference not set to an instance of an
  at System.String.memcpy2 (System.Byte* dest, System.Byte* src, Int32 size)
[0x00000] in <filename unknown>:0 
  at System.String.memcpy (System.Byte* dest, System.Byte* src, Int32 size)
[0x00000] in <filename unknown>:0 
  at (wrapper unknown)
  at (wrapper managed-to-native)
System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,object)
(IntPtr media) [0x00000] in <filename unknown>:0

Structure is defined as below:

internal class libvlc_media_track_info_t {
    // fourcc
    public uint i_codec;
    public int i_id;

    public libvlc_track_t i_type;

    // video codec info
    public int i_profile;
    public int i_level;

    public uint i_channels;
    public uint i_rate;

    public uint i_height;
    public uint i_width;

Pointer passed to PtrToStructure isn't zero. Saying that I'm not sure if the
pointer passed to the method points to a valid structure, because first test I
wrote _doesn't fail_:

public void TestMonoBugDoesntFail() {
    IntPtr structPointer =
    try {
        libvlc_media_track_info_t instance = (libvlc_media_track_info_t)
    } finally {

However, exception is reproducing all the time I run this test:

public void TestMonoBugFails() {
    libvlc_media_track_info_t instance = (libvlc_media_track_info_t)
        Marshal.PtrToStructure(new IntPtr(0xA),

I think there should be something more than NullReferenceException. Maybe
additional check could help to understand the cause of the problem - invalid
pointer address.

Although documentation doesn't tell about NullReferenceException:


Reproducible: Always

Steps to Reproduce:
Run last test provided in details.
Actual Results:  

Expected Results:  
ArgumentException probably?

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