[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


https://bugzilla.novell.com/show_bug.cgi?id=662994

https://bugzilla.novell.com/show_bug.cgi?id=662994#c0


           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
object
  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)
DZ.MediaPlayer.Vlc.Internal.Interop.libvlc_media_track_info_t:PtrToStructure
(intptr,object)
  at (wrapper managed-to-native)
System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,object)
  at
DZ.MediaPlayer.Vlc.Internal.Interop.LibVlcInterop.libvlc_media_get_tracks_info
(IntPtr media) [0x00000] in <filename unknown>:0

Structure is defined as below:

[StructLayout(LayoutKind.Explicit)]
internal class libvlc_media_track_info_t {
    // fourcc
    [FieldOffset(0)]
    public uint i_codec;
    [FieldOffset(4)]
    public int i_id;

    [FieldOffset(8)]
    public libvlc_track_t i_type;

    // video codec info
    [FieldOffset(12)]
    public int i_profile;
    [FieldOffset(16)]
    public int i_level;

    [FieldOffset(20)]
    public uint i_channels;
    [FieldOffset(24)]
    public uint i_rate;

    [FieldOffset(20)]
    public uint i_height;
    [FieldOffset(24)]
    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_:

[Test]
public void TestMonoBugDoesntFail() {
    IntPtr structPointer =
Marshal.AllocHGlobal(Marshal.SizeOf(typeof(libvlc_media_track_info_t)));
    try {
        libvlc_media_track_info_t instance = (libvlc_media_track_info_t)
            Marshal.PtrToStructure(structPointer,
typeof(libvlc_media_track_info_t));
    } finally {
        Marshal.FreeHGlobal(structPointer);
    }
}

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

[Test]
public void TestMonoBugFails() {
    libvlc_media_track_info_t instance = (libvlc_media_track_info_t)
        Marshal.PtrToStructure(new IntPtr(0xA),
typeof(libvlc_media_track_info_t));
}

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:
http://www.go-mono.com/docs/monodoc.ashx?link=M%3aSystem.Runtime.InteropServices.Marshal.PtrToStructure(System.IntPtr%2cSystem.Type)

Thanks.

Reproducible: Always

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

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