diff --git a/tests/elf.rs b/tests/elf.rs index d12c4b4c3..af9c1122c 100644 --- a/tests/elf.rs +++ b/tests/elf.rs @@ -75,6 +75,36 @@ fn parse_text_section_size_lazy(base: &[u8]) -> Result { Err("Didn't find text section") } +fn parse_impl_text_section_size_lazy(base: &[u8]) -> Result { + let header = Elf::parse_header(base).map_err(|_| "parse elf header error")?; + + use goblin::container::{Container, Ctx}; + use goblin::elf::SectionHeader; + + let ctx = Ctx { + le: scroll::Endian::Little, + container: Container::Big, + }; + + let sh_from_orig = + SectionHeader::parse(base, header.e_shoff as usize, header.e_shnum as usize, ctx) + .map_err(|_| "parse() section headers error")?; + + let sh_from_offset = SectionHeader::parse_impl( + &base[header.e_shoff as usize..], + 0, + header.e_shnum as usize, + ctx, + ) + .map_err(|_| "parse_impl() section headers error")?; + + if sh_from_orig == sh_from_offset { + return Ok(true); + } + + Err("Mismatching offset reading") +} + #[test] fn test_parse_gnu_hash_section_64bit() { static ALIGNED_DATA: &AlignedData<[u8]> = @@ -148,6 +178,13 @@ fn test_parse_text_section_size_lazy() { assert_eq!(parse_text_section_size_lazy(&ALIGNED_DATA.0), Ok(0x126)); } +#[test] +fn test_parse_impl_text_section_size_lazy() { + static ALIGNED_DATA: &AlignedData<[u8]> = + &AlignedData(*include_bytes!("bins/elf/gnu_hash/hello.so")); + assert_eq!(parse_impl_text_section_size_lazy(&ALIGNED_DATA.0), Ok(true)); +} + #[test] fn test_oom() { use goblin::container::{Container, Ctx};