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

Throw BadImageFormatException when missing PE metadata #6270

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/Tasks/AssemblyDependency/AssemblyInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,21 @@ private void CorePopulateMetadata()
using (var stream = File.OpenRead(_sourceFile))
using (var peFile = new PEReader(stream))
{
bool hasMetadata = false;
try
{
hasMetadata = peFile.HasMetadata;
KirillOsenkov marked this conversation as resolved.
Show resolved Hide resolved
}
finally
{
if (!hasMetadata)
{
throw new BadImageFormatException(string.Format(CultureInfo.CurrentCulture,
KirillOsenkov marked this conversation as resolved.
Show resolved Hide resolved
AssemblyResources.GetString("ResolveAssemblyReference.AssemblyDoesNotContainPEMetadata"),
_sourceFile));
}
}

var metadataReader = peFile.GetMetadataReader();

var assemblyReferences = metadataReader.AssemblyReferences;
Expand Down