From 5a96896c33127d75fbd264fb684e625acee8e14b Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 18 Mar 2024 09:56:16 +0100 Subject: [PATCH] fix: bug in `parse_dir_entries`. --- lib/src/modules/pe/parser.rs | 2 +- ...4742c0fad490cb2165f371f53b61941eedf072.out | 32 ------------------- ...6ad42ccfb04ccedd3ada1e8c26939c726a4c8e.out | 20 ------------ 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/lib/src/modules/pe/parser.rs b/lib/src/modules/pe/parser.rs index 621ccc5c7..fd41b3001 100644 --- a/lib/src/modules/pe/parser.rs +++ b/lib/src/modules/pe/parser.rs @@ -1365,7 +1365,7 @@ impl<'a> PE<'a> { fn parse_dir_entries(&self) -> Option> { // The number of directory entries is limited to MAX_DIR_ENTRIES. - let num_dir_entries = usize::max( + let num_dir_entries = usize::min( self.optional_hdr.number_of_rva_and_sizes as usize, Self::MAX_DIR_ENTRIES, ); diff --git a/lib/src/modules/pe/tests/testdata/29eeeecf2c458ea3da1ce9d6d54742c0fad490cb2165f371f53b61941eedf072.out b/lib/src/modules/pe/tests/testdata/29eeeecf2c458ea3da1ce9d6d54742c0fad490cb2165f371f53b61941eedf072.out index 289dc4387..5e8ebf4be 100644 --- a/lib/src/modules/pe/tests/testdata/29eeeecf2c458ea3da1ce9d6d54742c0fad490cb2165f371f53b61941eedf072.out +++ b/lib/src/modules/pe/tests/testdata/29eeeecf2c458ea3da1ce9d6d54742c0fad490cb2165f371f53b61941eedf072.out @@ -202,38 +202,6 @@ data_directories: size: 0 - virtual_address: 0 size: 0 - - virtual_address: 2019914798 - size: 116 - - virtual_address: 340336 - size: 4096 - - virtual_address: 340480 - size: 1024 - - virtual_address: 0 - size: 0 - - virtual_address: 0 - size: 1610612768 - - virtual_address: 1952539694 - size: 97 - - virtual_address: 42620 - size: 348160 - - virtual_address: 40960 - size: 341504 - - virtual_address: 0 - size: 0 - - virtual_address: 0 - size: 3221225536 - - virtual_address: 1936487470 - size: 0 - - virtual_address: 9 - size: 393216 - - virtual_address: 512 - size: 382464 - - virtual_address: 0 - size: 0 - - virtual_address: 0 - size: 3221225536 - - virtual_address: 1920168494 - size: 99 resource_timestamp: 0 # 1970-01-01 00:00:00 UTC resource_version: major: 0 diff --git a/lib/src/modules/pe/tests/testdata/af3f20a9272489cbef4281c8c86ad42ccfb04ccedd3ada1e8c26939c726a4c8e.out b/lib/src/modules/pe/tests/testdata/af3f20a9272489cbef4281c8c86ad42ccfb04ccedd3ada1e8c26939c726a4c8e.out index 661121854..544ad2583 100644 --- a/lib/src/modules/pe/tests/testdata/af3f20a9272489cbef4281c8c86ad42ccfb04ccedd3ada1e8c26939c726a4c8e.out +++ b/lib/src/modules/pe/tests/testdata/af3f20a9272489cbef4281c8c86ad42ccfb04ccedd3ada1e8c26939c726a4c8e.out @@ -106,26 +106,6 @@ data_directories: size: 2832 - virtual_address: 0 size: 0 - - virtual_address: 1952805678 - size: 28789 - - virtual_address: 14272 - size: 512 - - virtual_address: 14272 - size: 512 - - virtual_address: 0 - size: 0 - - virtual_address: 0 - size: 1615855648 - - virtual_address: 1818587694 - size: 25455 - - virtual_address: 32 - size: 14784 - - virtual_address: 32 - size: 14784 - - virtual_address: 0 - size: 0 - - virtual_address: 0 - size: 1108344896 is_signed: true signatures: - subject: "/C=AT/O=Security Coding Factory GmbH/OU=Security Coding Factory Certificate Authority/CN=Security Coding Factory Software CA"