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

Hardened checks for resource folder parsing #1189

Merged
merged 1 commit into from
Jan 18, 2024
Merged
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
8 changes: 5 additions & 3 deletions src/pelib/ResourceDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,15 @@ namespace PeLib
// 7dfc75ade04a0deb55dfbf87baff2306e625c5280748856f69f2f43599615249
// * IMAGE_RESOURCE_DIRECTORY::Characteristics != 0
// * IMAGE_RESOURCE_DIRECTORY::NumberOfIdEntries == 0x8000
// ef866e5eeacd096c4dab73c6d2b098253ba46f1ecf45467e6d65a8e1a75b4ca9
// * The whole resource section is filled with an invalid pattern
// We artificially limit the allowed number of resource entries.
// If exceeded, we don't stop resource parsing, but rather ignore the resource and move on
// in order to be in sync with YARA
unsigned int uiNumberOfEntries = header.NumberOfNamedEntries + header.NumberOfIdEntries;
if((header.NumberOfNamedEntries > PELIB_MAX_RESOURCE_ENTRIES) ||
(header.NumberOfIdEntries > PELIB_MAX_RESOURCE_ENTRIES) ||
(uiNumberOfEntries > PELIB_MAX_RESOURCE_ENTRIES))
if((header.NumberOfNamedEntries >= PELIB_MAX_RESOURCE_ENTRIES) ||
(header.NumberOfIdEntries >= PELIB_MAX_RESOURCE_ENTRIES) ||
(uiNumberOfEntries >= PELIB_MAX_RESOURCE_ENTRIES))
return ERROR_SKIP_RESOURCE;

// Add the total number of entries to the occupied range
Expand Down
Loading