Browse Source

Fix #1615: Handle nil tokens gracefully.

pull/1633/head
Siegfried Pammer 6 years ago
parent
commit
6b075326f0
  1. 3
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 6
      ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs

3
ICSharpCode.Decompiler/IL/ILReader.cs

@ -124,9 +124,10 @@ namespace ICSharpCode.Decompiler.IL @@ -124,9 +124,10 @@ namespace ICSharpCode.Decompiler.IL
EntityHandle ReadAndDecodeMetadataToken()
{
int token = reader.ReadInt32();
if (token < 0) {
if (token <= 0) {
// SRM uses negative tokens as "virtual tokens" and can get confused
// if we manually create them.
// Row-IDs < 1 are always invalid.
throw new BadImageFormatException("Invalid metadata token");
}
return MetadataTokens.EntityHandle(token);

6
ICSharpCode.Decompiler/IL/InstructionOutputExtensions.cs

@ -69,8 +69,10 @@ namespace ICSharpCode.Decompiler.IL @@ -69,8 +69,10 @@ namespace ICSharpCode.Decompiler.IL
public static void WriteTo(this EntityHandle entity, PEFile module, ITextOutput output, Metadata.GenericContext genericContext, ILNameSyntax syntax = ILNameSyntax.Signature)
{
if (entity.IsNil)
throw new ArgumentNullException(nameof(entity));
if (entity.IsNil) {
output.Write("<nil>");
return;
}
if (module == null)
throw new ArgumentNullException(nameof(module));
var metadata = module.Metadata;

Loading…
Cancel
Save