From 4caddf09c0c40c201adc8c9141f3538efdafff22 Mon Sep 17 00:00:00 2001 From: daladim Date: Mon, 16 Aug 2021 17:05:29 +0200 Subject: [PATCH 1/2] Fixed reading PE section data for contiguous sections Usually, sections are padded, but when they're not, a bug prevented accesses to the first byte of some sections --- src/read/pe/section.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/read/pe/section.rs b/src/read/pe/section.rs index a91dbdb9..e1ba4367 100644 --- a/src/read/pe/section.rs +++ b/src/read/pe/section.rs @@ -341,7 +341,12 @@ impl pe::ImageSectionHeader { let section_va = self.virtual_address.get(LE); let offset = va.checked_sub(section_va)?; let section_data = self.pe_data(data).ok()?; - section_data.get(offset as usize..) + if (offset as usize) < section_data.len() { + section_data.get(offset as usize..) + } else { + // We're calling `.get(i..)` with a range. In case i == offset.len(), this will return Some([]), not None + None + } } } From 9e6fe4a26950cc682db2dce2cb3c39cb588d08e1 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Tue, 17 Aug 2021 11:05:13 +1000 Subject: [PATCH 2/2] Update src/read/pe/section.rs --- src/read/pe/section.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/read/pe/section.rs b/src/read/pe/section.rs index e1ba4367..edcf85df 100644 --- a/src/read/pe/section.rs +++ b/src/read/pe/section.rs @@ -344,7 +344,7 @@ impl pe::ImageSectionHeader { if (offset as usize) < section_data.len() { section_data.get(offset as usize..) } else { - // We're calling `.get(i..)` with a range. In case i == offset.len(), this will return Some([]), not None + // We're calling `.get(i..)` with a range. In case i == section_data.len(), this will return Some([]), not None None } }