Skip to content

Commit

Permalink
Merge pull request #912 from avast/LZ_issue_911
Browse files Browse the repository at this point in the history
Fixed issue #911
  • Loading branch information
s3rvac authored Jan 6, 2021
2 parents ec5cd88 + 28505dd commit d8f666b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
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

0 comments on commit d8f666b

Please sign in to comment.