Fixed issue #911

This commit is contained in:
Ladislav Zezula 2021-01-06 09:11:33 +01:00
parent ec5cd887e0
commit 28505dd910
2 changed files with 3 additions and 8 deletions

View File

@ -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
{

View File

@ -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));
@ -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)
@ -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);
}