Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ private EcmaModule AddModule(string filePath, string expectedSimpleName, bool us
throw new NotSupportedException($"Error: C++/CLI is not supported: '{filePath}'");
#endif

pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder()) ?? OpenAssociatedSymbolFile(filePath, peReader);
pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder())
?? OpenAssociatedSymbolFile(filePath, peReader);
}
else
{
Expand Down Expand Up @@ -327,7 +328,7 @@ private PdbSymbolReader OpenAssociatedSymbolFile(string peFilePath, PEReader peR
string pdbFileName = null;
BlobContentId pdbContentId = default;

foreach (DebugDirectoryEntry debugEntry in peReader.ReadDebugDirectory())
foreach (DebugDirectoryEntry debugEntry in peReader.SafeReadDebugDirectory())
{
if (debugEntry.Type != DebugDirectoryEntryType.CodeView)
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Reflection.PortableExecutable;

namespace Internal.TypeSystem
{
public static class PortableExecutableMethodExtensions
{
public static ImmutableArray<DebugDirectoryEntry> SafeReadDebugDirectory(this PEReader peReader)
{
int actualDbgDirSize = peReader.PEHeaders.PEHeader.DebugTableDirectory.Size;

// This comes from the Size property of the DebugDirectoryEntry class.
const int expectedDbgDirSizeBase = 28;

if (actualDbgDirSize % expectedDbgDirSizeBase != 0)
return ImmutableArray<DebugDirectoryEntry>.Empty;

return peReader.ReadDebugDirectory();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static PdbSymbolReader TryOpen(string pdbFilename, MetadataStringDecoder

public static PdbSymbolReader TryOpenEmbedded(PEReader peReader, MetadataStringDecoder stringDecoder)
{
foreach (DebugDirectoryEntry debugEntry in peReader.ReadDebugDirectory())
foreach (DebugDirectoryEntry debugEntry in peReader.SafeReadDebugDirectory())
{
if (debugEntry.Type != DebugDirectoryEntryType.EmbeddedPortablePdb)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection.PortableExecutable;

using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;
using System.IO;
using System.Collections.Immutable;
Expand Down Expand Up @@ -250,7 +251,7 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
return new ObjectData(Array.Empty<byte>(), Array.Empty<Relocation>(), 1, new ISymbolDefinitionNode[] { this });
}

ImmutableArray<DebugDirectoryEntry> entries = _module.PEReader.ReadDebugDirectory();
ImmutableArray<DebugDirectoryEntry> entries = _module.PEReader.SafeReadDebugDirectory();
Debug.Assert(entries != null && _debugEntryIndex < entries.Length);

DebugDirectoryEntry sourceDebugEntry = entries[_debugEntryIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int GetNumDebugDirectoryEntriesInModule()
if (_module == null)
return 0;

ImmutableArray<DebugDirectoryEntry> entries = _module.PEReader.ReadDebugDirectory();
ImmutableArray<DebugDirectoryEntry> entries = _module.PEReader.SafeReadDebugDirectory();
return entries == null ? 0 : entries.Length;
}

Expand All @@ -99,8 +99,9 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
builder.AddSymbol(this);

ImmutableArray<DebugDirectoryEntry> entries = ImmutableArray<DebugDirectoryEntry>.Empty;

if (_module != null)
entries = _module.PEReader.ReadDebugDirectory();
entries = _module.PEReader.SafeReadDebugDirectory();

int numEntries = GetNumDebugDirectoryEntriesInModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Version>1.4.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\Common\TypeSystem\Common\ArrayMethod.Diagnostic.cs">
<Link>TypeSystem\Common\ArrayMethod.Diagnostic.cs</Link>
Expand Down Expand Up @@ -359,6 +360,9 @@
<Compile Include="..\..\Common\TypeSystem\Common\RuntimeInterfacesAlgorithm.cs">
<Link>TypeSystem\Common\RuntimeInterfacesAlgorithm.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\PortableExecutableMethodExtensions.cs">
<Link>Compiler\PortableExecutableMethodExtensions.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Ecma\CustomAttributeTypeProvider.cs">
<Link>Ecma\CustomAttributeTypeProvider.cs</Link>
</Compile>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/dotnet-pgo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ static int InnerProcessTraceFileMain(CommandLineOptions commandLineOptions)
bool matched = false;
bool mismatch = false;
bool mismatchHandled = false;
foreach (var debugEntry in ecmaModule.PEReader.ReadDebugDirectory())
foreach (DebugDirectoryEntry debugEntry in ecmaModule.PEReader.SafeReadDebugDirectory())
{
if (debugEntry.Type == DebugDirectoryEntryType.CodeView)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private PdbSymbolReader OpenAssociatedSymbolFile(string peFilePath, PEReader peR
string pdbFileName = null;
BlobContentId pdbContentId = default;

foreach (DebugDirectoryEntry debugEntry in peReader.ReadDebugDirectory())
foreach (DebugDirectoryEntry debugEntry in peReader.SafeReadDebugDirectory())
{
if (debugEntry.Type != DebugDirectoryEntryType.CodeView)
continue;
Expand Down