Fix for IndexOutOfRangeException in ILReader.ReadOpCode() (#81)

* Allow testing internals

* Add ILReaderTests

* Skip inline operands in IL
This commit is contained in:
Aristarkh Zagorodnikov
2019-01-29 18:09:08 +03:00
committed by Ben Adams
parent cdf53b2655
commit adef3aa266
4 changed files with 97 additions and 1 deletions

View File

@@ -27,4 +27,9 @@
</PackageReference>
</ItemGroup>
<ItemGroup Label="TestInternalsVisibleTo">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>$(AssemblyName).Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001005532489e147c0de0c5872048d20f7acf99d172a599d217950eba8fdbd1f98fa5ac47901b076d2bd7da8d436e6b5d6292694902e9748514bb0c3b17e6a0e0386f22447847c1c5cd9e034f79a8fe1c120a12785f7f79617414e63861cf13d6fd1cbb4211b87202c6a52c1e22962a6bd310413c37ca440fad14ab8422707517fbae</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>

View File

@@ -41,6 +41,7 @@ namespace System.Diagnostics.Internal
MemberInfo ReadOperand(OpCode code, MethodBase methodInfo)
{
MetadataToken = 0;
int inlineLength;
switch (code.OperandType)
{
case OperandType.InlineMethod:
@@ -64,7 +65,47 @@ namespace System.Diagnostics.Internal
// Can return System.ArgumentException : Token xxx is not a valid MemberInfo token in the scope of module xxx.dll
return null;
}
case OperandType.InlineNone:
inlineLength = 0;
break;
case OperandType.ShortInlineBrTarget:
case OperandType.ShortInlineVar:
inlineLength = 1;
break;
case OperandType.InlineVar:
inlineLength = 2;
break;
case OperandType.InlineBrTarget:
case OperandType.InlineField:
case OperandType.InlineI:
case OperandType.InlineString:
case OperandType.InlineSig:
case OperandType.InlineSwitch:
case OperandType.InlineTok:
case OperandType.InlineType:
case OperandType.ShortInlineR:
inlineLength = 4;
break;
case OperandType.InlineI8:
case OperandType.InlineR:
inlineLength = 8;
break;
default:
// Can return System.ArgumentException : Unexpected operand type xxx
return null;
}
for (var i = 0; i < inlineLength; i++)
{
ReadByte();
}
return null;
}