Skip to content

Access violation when using Vector3 array with default values #55623

Closed

Description

@brianpopow

Description

When accessing a array of Vector3 with Vector3.Zero or default the dotnet crashes without any error message.
Looking at the crashdump the error seems to be a AccessViolation

Unhandled exception at 0x00007FFA24E33E10 (coreclr.dll) in dotnet.exe.18068.dmp: 0xC0000005: Access violation reading location 0x0000000000000009.

A minimal reproduction looks like this:

public static object[] MatrixConversionData =
{
     Vector3.Zero
};

public static Vector3[] TestData =
{
    default,
    Vector3.Zero
};

static void Main(string[] args)
{
    Console.WriteLine(TestData[0]);
    Console.WriteLine(TestData[1]);
}

The issue seems to only happen with netcoreapp2.1 and not with netcoreapp3.1 or net5.0.
Also this only happens with a Release build.

Configuration

version of .NET: 5.0.301 and 6.0.100-preview.5.21302.13
OS: windows 10, x64

Regression?

I am not sure if it is a new issue. Because it happens with 5.0.301 and 6.0.100.preview, i dont think so.

Other information

Defining the unused array MatrixConversionData seems to be somehow important. Without it it works fine.

Activity

  1. ghost added
    untriaged
    on Jul 14, 2021
  2. added
    area-CodeGen-coreclr
    on Jul 14, 2021
  3. EgorBo commented on Jul 14, 2021

    @EgorBo
    Member

    hm.. I can reproduce this issue on .NET 6.0 in VS 16.11 when debugger is attached.

  4. EgorBo commented on Jul 14, 2021

    @EgorBo
    Member

    Perhaps, it's the same as #54025

  5. EgorBo commented on Jul 14, 2021

    @EgorBo
    Member
  6. added and removed
    area-CodeGen-coreclr
    on Jul 14, 2021
  7. hoyosjs commented on Jul 15, 2021

    @hoyosjs
    Member

    @EgorBo on 2.1 - which is what was reported - crashes in a jit helper. That being said, 2.1 is out of support on August - and I think that means the snap date is past.

    00 00000009`e297ce38 00007ffb`ce601917     coreclr!JIT_BoxFastMP_InlineGetThread+0x60 [C:\a\1\s\src\vm\amd64\JitHelpers_InlineGetThread.asm @ 98] 
    01 00000009`e297ce40 00007ffc`2e123033     gh55623_vector21!gh55623_vector21.Program..cctor()+0x47 [E:\mocks\gh55623-vector21\Program.cs @ 8] 
    02 00000009`e297ce90 00007ffc`2dfe5d6c     coreclr!CallDescrWorkerInternal+0x83 [C:\a\1\s\src\vm\amd64\CallDescrWorkerAMD64.asm @ 101] 
    03 00000009`e297ced0 00007ffc`2dfe5d13     coreclr!DispatchCallDebuggerWrapper+0x20 [c:\a\1\s\src\vm\callhelpers.cpp @ 172] 
    04 00000009`e297cf30 00007ffc`2dfe5be4     coreclr!DispatchCallSimple+0x63 [c:\a\1\s\src\vm\callhelpers.cpp @ 232] 
    05 00000009`e297cfc0 00007ffc`2dfe4b4b     coreclr!MethodTable::RunClassInitEx+0x12c [c:\a\1\s\src\vm\methodtable.cpp @ 3333] 
    06 00000009`e297d100 00007ffc`2dfe4efc     coreclr!MethodTable::DoRunClassInitThrowing+0x29b [c:\a\1\s\src\vm\methodtable.cpp @ 3565] 
    07 00000009`e297dba0 00007ffc`2e0f5c91     coreclr!MethodTable::CheckRunClassInitThrowing+0x110 [c:\a\1\s\src\vm\methodtable.cpp @ 3723] 
    08 00000009`e297dbd0 00007ffb`ce60183b     coreclr!JIT_GetSharedNonGCStaticBase_Helper+0xa1 [c:\a\1\s\src\vm\jithelpers.cpp @ 1451] 
    09 00000009`e297dd40 00007ffc`2e123033     gh55623_vector21!gh55623_vector21.Program.Main(System.String[])+0x2b [E:\mocks\gh55623-vector21\Program.cs @ 21] 
    0a 00000009`e297dd80 00007ffc`2e012773     coreclr!CallDescrWorkerInternal+0x83 [C:\a\1\s\src\vm\amd64\CallDescrWorkerAMD64.asm @ 101] 
    0b (Inline Function) --------`--------     coreclr!CallDescrWorkerWithHandler+0x52 [c:\a\1\s\src\vm\callhelpers.cpp @ 78] 
    0c 00000009`e297ddc0 00007ffc`2e07dcd6     coreclr!MethodDescCallSite::CallTargetWorker+0x273 [c:\a\1\s\src\vm\callhelpers.cpp @ 628] 
    0d (Inline Function) --------`--------     coreclr!MethodDescCallSite::Call+0xb [c:\a\1\s\src\vm\callhelpers.h @ 433] 
    0e 00000009`e297df00 00007ffc`2e0c02d8     coreclr!RunMain+0x216 [c:\a\1\s\src\vm\assembly.cpp @ 1707] 
    0f 00000009`e297e160 00007ffc`2e0bfe8a     coreclr!Assembly::ExecuteMainMethod+0x150 [c:\a\1\s\src\vm\assembly.cpp @ 1817] 
    10 00000009`e297e440 00007ffc`2e0bfc29     coreclr!CorHost2::ExecuteAssembly+0x1fa [c:\a\1\s\src\vm\corhost.cpp @ 491] 
    11 00000009`e297e530 00007ffc`32abfed0     coreclr!coreclr_execute_assembly+0xe9 [c:\a\1\s\src\dlls\mscoree\unixinterface.cpp @ 407] 
    12 00000009`e297e5d0 00007ffc`32ac06cd     hostpolicy!run+0xfd0
    13 00000009`e297eb80 00007ffc`44e1e138     hostpolicy!corehost_main+0x7d
    14 00000009`e297ed00 00007ffc`44e26e5a     hostfxr!execute_app+0x1d8
    15 00000009`e297edd0 00007ffc`44e24d72     hostfxr!fx_muxer_t::read_config_and_execute+0xb7a
    16 00000009`e297f8a0 00007ffc`44e23bb6     hostfxr!fx_muxer_t::handle_exec_host_command+0x242
    17 00000009`e297f950 00007ffc`44e1ed75     hostfxr!fx_muxer_t::execute+0x346
    18 00000009`e297faa0 00007ff6`fb7a9c40     hostfxr!hostfxr_main_startupinfo+0x95
    19 00000009`e297fba0 00007ff6`fb7ae6e9     apphost!run+0x370
    1a (Inline Function) --------`--------     apphost!invoke_main+0x22 [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 79] 
    1b 00000009`e297fd10 00007ffc`c8a17034     apphost!__scrt_common_main_seh+0x11d [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 253] 
    1c 00000009`e297fd50 00007ffc`c9f62651     KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64] 
    1d 00000009`e297fd80 00000000`00000000     ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153]
    

    Particularly for this IL/assembly in the constructor:

    IL_0000: ldc.i4.1 
    IL_0001: newarr System.Object
    IL_0006: dup 
    IL_0007: ldc.i4.0 
    IL_0008: call valuetype [System.Numerics.Vectors]System.Numerics.Vector3 System.Numerics.Vector3::get_Zero()
    IL_000d: box System.Numerics.Vector3
    IL_0012: stelem.ref 
    IL_0013: stsfld gh55623_vector21.Program::MatrixConversionData
    00007ffb`cda718eb 48b9d0471c2dfc7f0000 mov rcx,offset System_Private_CoreLib+0xa147d0 (00007ffc`2d1c47d0) (MT: System.Object[])
    00007ffb`cda718f5 ba01000000      mov     edx,1
    00007ffb`cda718fa e80126b05f      call    coreclr!JIT_NewArr1OBJ_MP_InlineGetThread (00007ffc`2d573f00)
    00007ffb`cda718ff 488945f0        mov     qword ptr [rbp-10h],rax
    00007ffb`cda71903 c4e17857c0      vxorps  xmm0,xmm0,xmm0
    00007ffb`cda71908 48b9506495cdfb7f0000 mov rcx,7FFBCD956450h (MT: System.Numerics.Vector3)
    00007ffb`cda71912 e89924b05f      call    coreclr!JIT_BoxFastMP_InlineGetThread (00007ffc`2d573db0)
    >>> 00007ffb`cda71917 488945e0        mov     qword ptr [rbp-20h],rax
    00007ffb`cda7191b 4c8b45e0        mov     r8,qword ptr [rbp-20h]
    00007ffb`cda7191f 488b4df0        mov     rcx,qword ptr [rbp-10h]
    00007ffb`cda71923 33d2            xor     edx,edx
    00007ffb`cda71925 e8c610b05f      call    coreclr!JIT_Stelem_Ref (00007ffc`2d5729f0)
    00007ffb`cda7192a 48b960290010a5010000 mov rcx,1A510002960h
    00007ffb`cda71934 488b55f0        mov     rdx,qword ptr [rbp-10h]
    00007ffb`cda71938 e8630fb05f      call    coreclr!JIT_CheckedWriteBarrier (00007ffc`2d5728a0)
    
    ; HCIMPL2(Object*, JIT_Box, CORINFO_CLASS_HANDLE type, void* unboxedData)
    NESTED_ENTRY JIT_BoxFastMP_InlineGetThread, _TEXT
            mov     rax, [rcx + OFFSETOF__MethodTable__m_pWriteableData]
    
            ; Check whether the class has not been initialized
            test    dword ptr [rax + OFFSETOF__MethodTableWriteableData__m_dwFlags], MethodTableWriteableData__enum_flag_Unrestored
            jnz     ClassNotInited
    
            mov     r8d, [rcx + OFFSET__MethodTable__m_BaseSize]
    
            ; m_BaseSize is guaranteed to be a multiple of 8.
    
            INLINE_GETTHREAD r11
            mov     r10, [r11 + OFFSET__Thread__m_alloc_context__alloc_limit]
            mov     rax, [r11 + OFFSET__Thread__m_alloc_context__alloc_ptr]
    
            add     r8, rax
    
            cmp     r8, r10
            ja      AllocFailed
    
            mov     [r11 + OFFSET__Thread__m_alloc_context__alloc_ptr], r8
            mov     [rax], rcx
    
            ; Check whether the object contains pointers
            test    dword ptr [rcx + OFFSETOF__MethodTable__m_dwFlags], MethodTable__enum_flag_ContainsPointers
            jnz     ContainsPointers
    
            ; We have no pointers - emit a simple inline copy loop
            ; Copy the contents from the end
            mov     ecx, [rcx + OFFSET__MethodTable__m_BaseSize]
            sub     ecx, 18h  ; sizeof(ObjHeader) + sizeof(Object) + last slot
    align 16
        CopyLoop:
            mov     r8, [rdx+rcx] <-- this is the issue, since this is rdx+rcx=0x9; not sure how. 
            mov     [rax+rcx+8], r8 
            sub     ecx, 8
            jge     CopyLoop
            REPRET
    
        ContainsPointers:
            ; Do call to CopyValueClassUnchecked(object, data, pMT)
            push_vol_reg rax
            alloc_stack 20h
            END_PROLOGUE
    
            mov     r8, rcx
            lea     rcx, [rax + 8]
            call    CopyValueClassUnchecked
    
            add     rsp, 20h
            pop     rax
            ret

    I couldn't repro anything particular under the debugger on 6.0.0-preview.5.21301.5. Moving back to codegen - although 2.1 is not very actionable. Let me know if you have any repros on the 6.0 issue.

  8. added
    area-CodeGen-coreclr
    and removed on Jul 15, 2021
  9. EgorBo commented on Jul 15, 2021

    @EgorBo
    Member

    @hoyosjs hm.. I updated my .NET 6.0 preview (I think it was Preview4) to 6 and can't reproduce it anymore. So I guess we can close this.

    Thanks for the investigation!

  10. brianpopow commented on Jul 15, 2021

    @brianpopow
    Author

    The issue seems to happen also for net472 and net48 (again only for Release and not in Debug mode)

  11. added
    needs-further-triage
    and removed
    untriaged
    on Jul 15, 2021
  12. added this to the 6.0.0 milestone on Jul 15, 2021
  13. EgorBo commented on Jul 27, 2021

    @EgorBo
    Member

    @brianpopow I'm not able to reproduce it for net472 and net48, but it does reproduce on netcoreapp2.1. However, all of these targets, as was noted, are no longer maintained. Are there any extra steps needed to reproduce it under .NET Framework and does it block you the way there is no workaround for it?

  14. assigned and unassigned on Jul 27, 2021
  15. brianpopow commented on Jul 27, 2021

    @brianpopow
    Author

    I'm not able to reproduce it for net472 and net48, but it does reproduce on netcoreapp2.1. However, all of these targets, as was noted, are no longer maintained. Are there any extra steps needed to reproduce it under .NET Framework and

    @EgorBo: Actually there are no extra steps need.

    does it block you the way there is no workaround for it?

    No it does not block me, I can work around it by not using Vector.Zero.

    Thanks for investigating!

  16. ghost locked as resolved and limited conversation to collaborators on Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrneeds-further-triage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions