Skip to content

Commit

Permalink
Add conditional check for PDB location
Browse files Browse the repository at this point in the history
File.OpenRead can throw if pdb.PdbLocation is a directory.

This can happen if (for some reason) the pdb file is not found.
In which case PdbLocation will return the working directory, causing
File.OpenRead to throw.
  • Loading branch information
Lukas Kohl committed Aug 5, 2024
1 parent 65ce486 commit 81e1bc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- NEW => new feature

## UNRELEASED
* BUG: Fix `TryGetPortablePdbMetadataReader` unexpectedly causes `UnauthorizedAccessException` error when the PDB file is missing. [1001](https://github.com/microsoft/binskim/pull/1001).

## **v4.3.0**
* DEP: Update `msdia140.dll` from 14.36.32532.0 to 14.40.33810.0. This update fixes the `System.AccessViolationException: Attempted to read or write protected memory` exception that occurs when reading certain PDB files. [996](https://github.com/microsoft/binskim/pull/996)
Expand Down
6 changes: 5 additions & 1 deletion src/BinaryParsers/PEBinary/PortableExecutable/PE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,11 @@ private bool TryGetPortablePdbMetadataReader(Pdb pdb, out MetadataReader pdbMeta
out MetadataReaderProvider pdbProvider,
out _))
{
pdbProvider = MetadataReaderProvider.FromPortablePdbStream(File.OpenRead(pdb.PdbLocation));
if (File.Exists(pdb.PdbLocation))
{
pdbProvider = MetadataReaderProvider.FromPortablePdbStream(File.OpenRead(pdb.PdbLocation));
}

if (pdbProvider == null)
{
pdbMetadataReader = null;
Expand Down

0 comments on commit 81e1bc9

Please sign in to comment.