Fix TableOutOfRangeException in Crossgen2 (#39653)
authorTomáš Rylek <trylek@microsoft.com>
Tue, 21 Jul 2020 10:03:17 +0000 (12:03 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Jul 2020 10:03:17 +0000 (12:03 +0200)
Fixes: https://github.com/dotnet/runtime/issues/39493

Turns out the compilation failure here wasn't caused by Managed C++,
it was due to a simple bug in the field RVA copy loop - reading
compressed 16-bit field indices as signed, not unsigned, from the
FieldRVA ECMA metadata table.

Thanks

Tomas

src/coreclr/src/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedFieldRvaNode.cs
src/coreclr/src/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMetadataBlobNode.cs

index 8adc734..e8596cf 100644 (file)
@@ -67,7 +67,7 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
                 int currentFieldRid;
                 if (compressedFieldRef)
                 {
-                    currentFieldRid = metadataBlob.ReadInt16();
+                    currentFieldRid = metadataBlob.ReadUInt16();
                 }
                 else
                 {
index 8f0ae42..b38dbfb 100644 (file)
@@ -84,7 +84,7 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
                 int fieldToken;
                 if (compressedFieldRef)
                 {
-                    fieldToken = reader.ReadInt16();
+                    fieldToken = reader.ReadUInt16();
                 }
                 else
                 {