Fix incorrect EHCount calculation (#24048)
authorLevi Broderick <GrabYourPitchforks@users.noreply.github.com>
Wed, 17 Apr 2019 03:12:12 +0000 (20:12 -0700)
committerJan Kotas <jkotas@microsoft.com>
Wed, 17 Apr 2019 03:12:12 +0000 (20:12 -0700)
src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs

index fb763a5..d26d97d 100644 (file)
@@ -724,7 +724,12 @@ namespace System.Reflection.Emit
 
                 if ((header & 0x40) != 0) // Fat
                 {
-                    EHCount = (BinaryPrimitives.ReadInt32LittleEndian(m_exceptionHeader.AsSpan(1)) - 4) / 24;
+                    // Positions 1..3 of m_exceptionHeader are a 24-bit little-endian integer.
+                    int size = m_exceptionHeader[3] << 16;
+                    size |= m_exceptionHeader[2] << 8;
+                    size |= m_exceptionHeader[1];
+
+                    EHCount = (size - 4) / 24;
                 }
                 else
                     EHCount = (m_exceptionHeader[1] - 2) / 12;