Skip to content

Commit d950c19

Browse files
authored
pe.section_table: Fixed getting section data tainted section lifetime (#493)
* Fixed getting section data tainted section lifetime * Added unit-test to test getting SectionTable::data
1 parent a5df149 commit d950c19

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/pe/section_table.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl SectionTable {
9999
Ok(table)
100100
}
101101

102-
pub fn data<'a, 'b: 'a>(&'a self, pe_bytes: &'b [u8]) -> error::Result<Option<Cow<'a, [u8]>>> {
102+
pub fn data<'b>(&self, pe_bytes: &'b [u8]) -> error::Result<Option<Cow<'b, [u8]>>> {
103103
let section_start: usize = self.pointer_to_raw_data.try_into().map_err(|_| {
104104
Error::Malformed(format!("Virtual address cannot fit in platform `usize`"))
105105
})?;
@@ -340,6 +340,19 @@ pub const IMAGE_SCN_MEM_WRITE: u32 = 0x8000_0000;
340340
mod tests {
341341
use super::*;
342342

343+
#[test]
344+
fn test_section_to_bytes() {
345+
let bytes = vec![0u8; 16];
346+
let r_bytes = {
347+
let mut section = SectionTable::default();
348+
section.pointer_to_raw_data = 4;
349+
section.size_of_raw_data = 4;
350+
section.virtual_size = 4;
351+
section.data(&bytes).unwrap().unwrap()
352+
};
353+
assert_eq!(*r_bytes, [0, 0, 0, 0])
354+
}
355+
343356
#[test]
344357
fn set_name_offset() {
345358
let mut section = SectionTable::default();

0 commit comments

Comments
 (0)