Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obfuscated file causes System.OutOfMemoryException #963

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Mono.Cecil.PE/ImageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ void ReadDebugHeader ()
AddressOfRawData = ReadInt32 (),
PointerToRawData = ReadInt32 (),
};

if (directory.PointerToRawData == 0 || directory.SizeOfData < 0) {

// directory.Characteristics <-- has to be 0 (https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-debug-section)
// if this is not the case, an obfuscation of the file could be the case resulting in wrong SizeOfData
if (directory.PointerToRawData == 0 || directory.Characteristics != 0 || directory.SizeOfData < 0) {
entries [i] = new ImageDebugHeaderEntry (directory, Empty<byte>.Array);
continue;
}
Expand Down
14 changes: 14 additions & 0 deletions Test/Mono.Cecil.Tests/ImageReadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ public void Net471TargetingAssembly ()
Assert.AreEqual (0, module.Image.SubSystemMinor);
});
}

[Test]
public void ObfuscatedAssembly ()
{
using (var image = GetResourceImage ("libhello_obfuscated.dll")) {
Assert.AreEqual (3, image.DebugHeader.Entries.Length);
Assert.AreEqual (67, image.DebugHeader.Entries[0].Data.Length);
Assert.AreEqual (0, image.DebugHeader.Entries[1].Data.Length);
Assert.AreEqual (0, image.DebugHeader.Entries[2].Data.Length);
}


}


[Test]
public void LocallyScopedConstantArray ()
Expand Down
Binary file not shown.