Skip to content

Commit 28505dd

Browse files
author
Ladislav Zezula
committed
Fixed issue #911
1 parent ec5cd88 commit 28505dd

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

include/retdec/pelib/PeLibAux.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace PeLib
162162
const std::uint32_t PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
163163
const std::uint32_t PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000;
164164
const std::uint32_t PELIB_IMAGE_RESOURCE_RVA_MASK = 0x7FFFFFFF;
165-
const std::uint16_t PELIB_MAX_RESOURCE_ENTRIES = 0xC000; // Maximum number of resource directory entries we consider OK
165+
const std::uint16_t PELIB_MAX_RESOURCE_ENTRIES = 0x8000; // Maximum number of resource directory entries we consider OK
166166

167167
enum : std::uint32_t
168168
{

src/pelib/ResourceDirectory.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ namespace PeLib
318318
// Invalid leaf.
319319
std::uint32_t uiRva = uiRsrcRva + uiOffset;
320320
if(uiRva > sizeOfImage)
321-
{
322321
return ERROR_INVALID_FILE;
323-
}
324322

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

332330
// No data or invalid leaf
331+
if(entry.OffsetToData == 0 && entry.Size == 0)
332+
return ERROR_INVALID_FILE;
333333
if(entry.OffsetToData > sizeOfImage || entry.Size > sizeOfImage)
334334
return ERROR_NONE;
335335
if((uiRsrcRva + entry.OffsetToData) >= sizeOfImage || (uiRsrcRva + entry.OffsetToData + entry.Size) > sizeOfImage)
@@ -1031,11 +1031,6 @@ namespace PeLib
10311031
std::uint32_t resDirRva = imageLoader.getDataDirRva(PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE);
10321032
std::uint32_t sizeOfImage = imageLoader.getSizeOfImage();
10331033

1034-
if(resDirRva >= sizeOfImage)
1035-
{
1036-
return ERROR_INVALID_FILE;
1037-
}
1038-
10391034
return m_rnRoot.read(imageLoader, resDirRva, 0, sizeOfImage, this);
10401035
}
10411036

0 commit comments

Comments
 (0)