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

Fixed issue #911 #912

Merged
merged 1 commit into from
Jan 6, 2021
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
2 changes: 1 addition & 1 deletion include/retdec/pelib/PeLibAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace PeLib
const std::uint32_t PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
const std::uint32_t PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000;
const std::uint32_t PELIB_IMAGE_RESOURCE_RVA_MASK = 0x7FFFFFFF;
const std::uint16_t PELIB_MAX_RESOURCE_ENTRIES = 0xC000; // Maximum number of resource directory entries we consider OK
const std::uint16_t PELIB_MAX_RESOURCE_ENTRIES = 0x8000; // Maximum number of resource directory entries we consider OK

enum : std::uint32_t
{
Expand Down
9 changes: 2 additions & 7 deletions src/pelib/ResourceDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ namespace PeLib
// Invalid leaf.
std::uint32_t uiRva = uiRsrcRva + uiOffset;
if(uiRva > sizeOfImage)
{
return ERROR_INVALID_FILE;
}

// Load the resource data entry
imageLoader.readImage(&entry, uiRva, sizeof(PELIB_IMAGE_RESOURCE_DATA_ENTRY));
Expand All @@ -330,6 +328,8 @@ namespace PeLib
m_data.clear();

// No data or invalid leaf
if(entry.OffsetToData == 0 && entry.Size == 0)
return ERROR_INVALID_FILE;
if(entry.OffsetToData > sizeOfImage || entry.Size > sizeOfImage)
return ERROR_NONE;
if((uiRsrcRva + entry.OffsetToData) >= sizeOfImage || (uiRsrcRva + entry.OffsetToData + entry.Size) > sizeOfImage)
Expand Down Expand Up @@ -1031,11 +1031,6 @@ namespace PeLib
std::uint32_t resDirRva = imageLoader.getDataDirRva(PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE);
std::uint32_t sizeOfImage = imageLoader.getSizeOfImage();

if(resDirRva >= sizeOfImage)
{
return ERROR_INVALID_FILE;
}

return m_rnRoot.read(imageLoader, resDirRva, 0, sizeOfImage, this);
}

Expand Down