Skip to content

Commit

Permalink
* Fixed high memory usage on samples with screwed up delayed imports
Browse files Browse the repository at this point in the history
* ImageLoader::stringLength() now stops properly on zero pages
  • Loading branch information
Ladislav Zezula authored and PeterMatula committed Jul 23, 2020
1 parent d55a5c8 commit d394a99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion include/retdec/pelib/DelayImportDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace PeLib
init();

// Keep loading until we encounter an entry filles with zeros
for(std::size_t i = 0;; i += sizeof(PELIB_IMAGE_DELAY_LOAD_DESCRIPTOR))
for(std::uint32_t i = 0;; i += sizeof(PELIB_IMAGE_DELAY_LOAD_DESCRIPTOR))
{
PELIB_IMAGE_DELAY_IMPORT_DIRECTORY_RECORD rec;

Expand All @@ -113,6 +113,10 @@ namespace PeLib
if(!imageLoader.readImage(&rec.delayedImport, rva + i, sizeof(PELIB_IMAGE_DELAY_LOAD_DESCRIPTOR)))
break;

// Valid delayed import entry starts either with 0 or 0x01
if(rec.delayedImport.Attributes & 0xFFFF0000)
break;

// Check for the termination entry
if(isTerminationEntry(rec.delayedImport))
break;
Expand Down
4 changes: 2 additions & 2 deletions src/pelib/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ uint32_t PeLib::ImageLoader::stringLength(
const uint8_t * dataPtr;
uint32_t rvaEndPage = (pageIndex + 1) * PELIB_PAGE_SIZE;

// If zero page, means we found an RVA with zero
// If zero page, means this is a zeroed page. This is the end of the string.
if(page.buffer.empty())
return rva;
break;
dataBegin = dataPtr = page.buffer.data() + (rva & (PELIB_PAGE_SIZE - 1));

// Perhaps the last page loaded?
Expand Down

0 comments on commit d394a99

Please sign in to comment.