Skip to content

Commit ed76f2d

Browse files
committed
[PE] Add a fast fail for malformed PE exception directory table size
Fixes Vector35/binaryninja#1472
1 parent 0c1ff77 commit ed76f2d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

view/pe/peview.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,10 +1753,15 @@ bool PEView::Init()
17531753
}
17541754
}
17551755

1756-
if (m_dataDirs[IMAGE_DIRECTORY_ENTRY_EXCEPTION].size % entrySize)
1756+
const auto& exceptionDir = m_dataDirs[IMAGE_DIRECTORY_ENTRY_EXCEPTION];
1757+
if (exceptionDir.size % entrySize)
17571758
throw PEFormatException("invalid table size");
1758-
numExceptionEntries = m_dataDirs[IMAGE_DIRECTORY_ENTRY_EXCEPTION].size / entrySize;
1759+
const auto imageSize = GetEnd() - GetStart();
1760+
if ((exceptionDir.virtualAddress > imageSize)
1761+
|| (exceptionDir.size > (imageSize - exceptionDir.virtualAddress)))
1762+
throw PEFormatException("too many exception entries, table size exceeds available memory range");
17591763

1764+
numExceptionEntries = exceptionDir.size / entrySize;
17601765
// This DataVariable can end up creating a large array and rendering this in LinearView currently has performance implications
17611766
// So instead we just create separate structures not in an array
17621767
Ref<Structure> exceptionEntryStruct = exceptionEntryBuilder.Finalize();

0 commit comments

Comments
 (0)