Closed
Description
Description
Creating a PEReader
for an invalid file type, such as an ELF can sometimes lead to a situation where the PEReader
thinks the file is valid and it will return garbage data, causing errors to occur downstream.
Attached is a zipfile containing an ELF which reproduces the issue, trimmed using dd
to reduce its filesize while still reproducing the issue.
Here's the code I'm running:
using System.Reflection.PortableExecutable;
var reader = new PEReader(File.OpenRead("path/to/invalid.so"));
Console.WriteLine(reader.HasMetadata);
Running the same code on a different ELF file throws a BadImageFormatException
, as expected.
Configuration
.NET SDK/Runtime info
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.102
Commit: 71365b4d42
Runtime Environment:
OS Name: debian
OS Version:
OS Platform: Linux
RID: debian-x64
Base Path: /usr/share/dotnet/sdk/5.0.102/
Host (useful for support):
Version: 5.0.2
Commit: cb5f173b96
.NET SDKs installed:
3.1.405 [/usr/share/dotnet/sdk]
5.0.102 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]