Repository: dotnet/runtime
File: src/coreclr/vm/jitinterface.cpp (C++)

Code before:
                        TypeLayoutCheck(pMT, pBlob, /* printDiff */ TRUE);
                    }
#endif

                    EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(-1, fatalErrorString.GetUnicode());
                    return FALSE;
                }
            }

            result = 1;
        }
        break;

    case READYTORUN_FIXUP_Continuation_Layout:
        {
            MethodTable* continuationTypeMethodTable = GetContinuationTypeFromLayout(pBlob);
            TypeHandle th = TypeHandle(continuationTypeMethodTable);
            result = (size_t)th.AsPtr();
        }
        break;

    case READYTORUN_FIXUP_Check_FieldOffset:
        {
            DWORD dwExpectedOffset = CorSigUncompressData(pBlob);

            FieldDesc * pFD = ZapSig::DecodeField(currentModule, pInfoModule, pBlob);
            _ASSERTE(!pFD->IsStatic());

            DWORD dwOffset = pFD->GetOffset();
            if (!pFD->IsFieldOfValueType())
                dwOffset += sizeof(Object);

            if (dwExpectedOffset != dwOffset)
                return FALSE;

            result = 1;
        }
        break;

    case READYTORUN_FIXUP_Verify_FieldOffset:
        {
            DWORD baseOffset = CorSigUncompressData(pBlob);
            DWORD fieldOffset = CorSigUncompressData(pBlob);
            FieldDesc* pField = ZapSig::DecodeField(currentModule, pInfoModule, pBlob);
            MethodTable *pEnclosingMT = pField->GetApproxEnclosingMethodTable();
            pEnclosingMT->CheckRestore();
            DWORD actualFieldOffset = pField->GetOffset();
            if (!pField->IsStatic() && !pField->IsFieldOfValueType())
            {
                actualFieldOffset += sizeof(Object);
            }

Review comment (bug):
GetContinuationTypeFromLayout can return nullptr if the GCLayout flag is not set. The result should be checked for null before using it to create a TypeHandle, otherwise it could lead to a null pointer dereference.
```suggestion
            if (continuationTypeMethodTable != NULL)
            {
                TypeHandle th = TypeHandle(continuationTypeMethodTable);
                result = (size_t)th.AsPtr();
            }
            else
            {
                result = 0;
            }
```

Code after:
                    {
                        _ASSERTE_MSG(false, fatalErrorString.GetUTF8());
                        // Run through the type layout logic again, after the assert, makes debugging easy
                        TypeLayoutCheck(pMT, pBlob, /* printDiff */ TRUE);
                    }
#endif

                    EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(-1, fatalErrorString.GetUnicode());
                    return FALSE;
                }
            }

            result = 1;
        }
        break;

    case READYTORUN_FIXUP_Continuation_Layout:
        {
            MethodTable* continuationTypeMethodTable = GetContinuationTypeFromLayout(pBlob, currentModule);
            if (continuationTypeMethodTable == NULL)
            {
                return FALSE;
            }

            TypeHandle th = TypeHandle(continuationTypeMethodTable);
            result = (size_t)th.AsPtr();
        }
        break;

    case READYTORUN_FIXUP_Check_FieldOffset:
        {
            DWORD dwExpectedOffset = CorSigUncompressData(pBlob);

            FieldDesc * pFD = ZapSig::DecodeField(currentModule, pInfoModule, pBlob);
            _ASSERTE(!pFD->IsStatic());

            DWORD dwOffset = pFD->GetOffset();
            if (!pFD->IsFieldOfValueType())
                dwOffset += sizeof(Object);

            if (dwExpectedOffset != dwOffset)
                return FALSE;

            result = 1;
        }
        break;

    case READYTORUN_FIXUP_Verify_FieldOffset:
        {
            DWORD baseOffset = CorSigUncompressData(pBlob);
            DWORD fieldOffset = CorSigUncompressData(pBlob);