diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index b89af61ee15de9..cd17fd6b5ae1a0 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -3304,8 +3304,9 @@ HRESULT CordbReJitILCode::Init(DacSharedReJitInfo* pSharedReJitInfo) m_cbLocalIL = ilCodeSize; IfFailRet(GetProcess()->SafeReadBuffer(m_codeRegionInfo, m_pLocalIL, FALSE /*throwOnError*/)); - // Check if this il code has exception clauses - if ((pMethodTinyHeader->Flags_CodeSize & CorILMethod_MoreSects) == 0) + // Check if this il code has exception clauses. A tiny header has no flags for extra sections: + // its upper bits are the code size, so CorILMethod_MoreSects only applies to a fat header. + if (isTinyHeader || (pMethodTinyHeader->Flags_CodeSize & CorILMethod_MoreSects) == 0) { return S_OK; // no EH, done initing } @@ -3358,14 +3359,16 @@ HRESULT CordbReJitILCode::Init(DacSharedReJitInfo* pSharedReJitInfo) // Read in the section header to see how many small clauses there are IMAGE_COR_ILMETHOD_SECT_SMALL sectionHeader = { 0 }; IfFailRet(GetProcess()->SafeReadStruct(ehClauseHeader, §ionHeader)); - ULONG32 m_cClauses = (sectionHeader.DataSize - 4) / sizeof(IMAGE_COR_ILMETHOD_SECT_SMALL); + // The small clauses start after the 2 byte section header and a 2 byte Reserved field + const ULONG32 cbSmallSectionHeader = offsetof(IMAGE_COR_ILMETHOD_SECT_EH_SMALL, Clauses); + m_cClauses = (sectionHeader.DataSize - cbSmallSectionHeader) / sizeof(IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL); if (m_cClauses > 10000) // sanity check the data before allocating { return CORDBG_E_TARGET_INCONSISTENT; } // Read in the clauses - TargetBuffer buffer(ehClauseHeader + sizeof(IMAGE_COR_ILMETHOD_SECT_SMALL), m_cClauses*sizeof(IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL)); + TargetBuffer buffer(ehClauseHeader + cbSmallSectionHeader, m_cClauses*sizeof(IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL)); NewArrayHolder pClauses = new (nothrow)IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL[m_cClauses]; if (pClauses == NULL) return E_OUTOFMEMORY;