Skip to content

Commit

Permalink
Update resource iteration (dotnet#4981)
Browse files Browse the repository at this point in the history
This changes resource iteration in `GetNextLevelResourceEntryRVA` to explicitly cast a potential overflow. It's safe since it will just not iterate any resources.
  • Loading branch information
hoyosjs authored Oct 14, 2024
1 parent 4a5a10d commit 5d515de
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/shared/debug/dbgutil/dbgutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,14 @@ HRESULT GetNextLevelResourceEntryRVA(ICorDebugDataTarget* pDataTarget,
IMAGE_RESOURCE_DIRECTORY resourceDirectory;
hr = ReadFromDataTarget(pDataTarget, moduleBaseAddress + resourceDirectoryRVA, (BYTE*)&resourceDirectory, sizeof(resourceDirectory));



// The ith resource directory entry is at offset 16 + 8i from the beginning of the resource
// directory table
WORD numNameEntries;
WORD numIDEntries;
if (SUCCEEDED(hr))
{
numNameEntries = resourceDirectory.NumberOfNamedEntries;
numIDEntries = resourceDirectory.NumberOfIdEntries;
// The ith resource directory entry is at offset 16 + 8i from the beginning of the resource
// directory table. First come named entries, followed by ID entries. We skip the former.
WORD beginIdEntries = resourceDirectory.NumberOfNamedEntries;
WORD endIdEntries = (WORD)(beginIdEntries + resourceDirectory.NumberOfIdEntries);

for (WORD i = numNameEntries; i < numNameEntries + numIDEntries; i++)
for (WORD i = beginIdEntries; i < endIdEntries; i++)
{
IMAGE_RESOURCE_DIRECTORY_ENTRY entry;
hr = ReadFromDataTarget(pDataTarget, moduleBaseAddress + resourceDirectoryRVA + sizeof(resourceDirectory) + sizeof(entry)*i,
Expand Down

0 comments on commit 5d515de

Please sign in to comment.