Skip to content

Commit 6aa9bd8

Browse files
Fix #3549: Do not crash on encountering nil tokens.
1 parent 967de58 commit 6aa9bd8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ICSharpCode.Decompiler/IL/ILReader.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ EntityHandle ReadAndDecodeMetadataToken()
212212
// Row-IDs < 1 are always invalid.
213213
throw new BadImageFormatException("Invalid metadata token");
214214
}
215-
return MetadataTokens.EntityHandle(token);
215+
var handle = MetadataTokens.EntityHandle(token);
216+
if (handle.IsNil)
217+
{
218+
// The runtime will crash with a BadImageFormatException when it encounters a row-ID of 0.
219+
// We assume the code following this instruction to be unreachable.
220+
throw new BadImageFormatException("Invalid metadata token");
221+
}
222+
return handle;
216223
}
217224

218225
IType ReadAndDecodeTypeReference()

0 commit comments

Comments
 (0)