Skip to content

Commit

Permalink
BUGFIX: Prevent exception when decoding to an invalid RID
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Feb 5, 2025
1 parent 6a4c633 commit 1e1f9b9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/IndexEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public MetadataToken DecodeIndex(uint codedIndex)
long tableIndex = codedIndex & _tableIndexBitMask;
uint rowIndex = codedIndex >> _tableIndexBitCount;

// When RID is invalid, force an invalid metadata token without throwing an exception.
// See also https://github.com/Washi1337/AsmResolver/issues/608
if (rowIndex > 0x00FFFFFF)
rowIndex = 0;

return new MetadataToken(tableIndex >= _tables.Length
? TableIndex.Module
: _tables[tableIndex],
Expand Down

1 comment on commit 1e1f9b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Results

Total Skipped Passed Failed
Unique 1944 0 💤 1944 ✅ 0 ❌
Total 5832 31 💤 5801 ✅ 0 ❌

Failing runs

Please sign in to comment.