Skip to content

Commit

Permalink
Added check for section alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladislav Zezula committed May 23, 2020
1 parent 39375e3 commit 718faf1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/retdec/pelib/PeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,17 @@ namespace PeLib
// The file size must be greater or equal to SizeOfImage
if(ulFileSize >= sizeOfImage)
{
dword sectionAlignment = peHeader().getSectionAlignment();
dword fileAlignment = peHeader().getFileAlignment();
dword sizeOfHeaders = peHeader().getSizeOfHeaders();

// SectionAlignment must be greater than file alignment
if(peHeader().getSectionAlignment() > peHeader().getFileAlignment())
if(sectionAlignment >= PELIB_PAGE_SIZE && sectionAlignment > fileAlignment)
{
// SizeOfHeaders must be smaller than SectionAlignment
if(peHeader().getSizeOfHeaders() < peHeader().getSectionAlignment())
if(sizeOfHeaders < sectionAlignment)
{
std::size_t headerDataSize = peHeader().getSectionAlignment() - peHeader().getSizeOfHeaders();
std::size_t headerDataSize = sectionAlignment - sizeOfHeaders;

// Read the entire after-header-data
std::vector<unsigned char> headerData(headerDataSize);
Expand Down

0 comments on commit 718faf1

Please sign in to comment.