mirror of
https://github.com/QuasarApp/pe-parse.git
synced 2025-05-08 01:29:34 +00:00
Merge pull request #20 from armbues/master
Checking for NumberOfRvaAndSizes to avoid DataDirectory overflow
This commit is contained in:
commit
8505e15e3f
@ -375,10 +375,14 @@ bool readOptionalHeader(bounded_buffer *b, optional_header_32 &header) {
|
||||
READ_DWORD(b, 0, header, LoaderFlags);
|
||||
READ_DWORD(b, 0, header, NumberOfRvaAndSizes);
|
||||
|
||||
if (header.NumberOfRvaAndSizes > NUM_DIR_ENTRIES) {
|
||||
header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES;
|
||||
}
|
||||
|
||||
for(::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) {
|
||||
::uint32_t c = (i*sizeof(data_directory));
|
||||
c+= _offset(optional_header_32, DataDirectory[0]);
|
||||
::uint32_t o;
|
||||
::uint32_t o;
|
||||
|
||||
o = c + _offset(data_directory, VirtualAddress);
|
||||
if(readDword(b, o, header.DataDirectory[i].VirtualAddress) == false) {
|
||||
@ -426,6 +430,10 @@ bool readOptionalHeader64(bounded_buffer *b, optional_header_64 &header) {
|
||||
READ_DWORD(b, 0, header, LoaderFlags);
|
||||
READ_DWORD(b, 0, header, NumberOfRvaAndSizes);
|
||||
|
||||
if (header.NumberOfRvaAndSizes > NUM_DIR_ENTRIES) {
|
||||
header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES;
|
||||
}
|
||||
|
||||
for(::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) {
|
||||
::uint32_t c = (i*sizeof(data_directory));
|
||||
c += _offset(optional_header_64, DataDirectory[0]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user