Add sample object with with > 0xff00 section headers
Also add unit tests that we properly parse e_shnum and e_shstrndx out of shdr0 in that case.
This commit is contained in:
parent
f747747929
commit
33e3435a7f
BIN
sample-objects/shnum.x86_64
Normal file
BIN
sample-objects/shnum.x86_64
Normal file
Binary file not shown.
@ -875,6 +875,30 @@ mod interface_tests {
|
||||
assert_eq!(shdr.sh_type, abi::SHT_GNU_HASH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shnum_and_shstrndx_in_shdr0() {
|
||||
let path = std::path::PathBuf::from("sample-objects/shnum.x86_64");
|
||||
let file_data = std::fs::read(path).expect("Could not read file.");
|
||||
let slice = file_data.as_slice();
|
||||
let file = ElfBytes::<AnyEndian>::minimal_parse(slice).unwrap();
|
||||
|
||||
let (shdrs, strtab) = file
|
||||
.section_headers_with_strtab()
|
||||
.expect("shdrs should be parsable")
|
||||
.expect("File should have shdrs");
|
||||
|
||||
let shdrs_len = shdrs.len();
|
||||
assert_eq!(shdrs_len, 0xFF15);
|
||||
|
||||
let shdr = shdrs.get(shdrs_len - 1).unwrap();
|
||||
let name = strtab
|
||||
.get(shdr.sh_name as usize)
|
||||
.expect("Failed to get section name");
|
||||
|
||||
assert_eq!(name, ".shstrtab");
|
||||
assert_eq!(shdr.sh_type, abi::SHT_STRTAB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_header_by_name() {
|
||||
let path = std::path::PathBuf::from("sample-objects/basic.x86_64");
|
||||
|
@ -700,6 +700,28 @@ mod interface_tests {
|
||||
assert_eq!(shdr_4.sh_type, abi::SHT_GNU_HASH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shnum_and_shstrndx_in_shdr0() {
|
||||
let path = std::path::PathBuf::from("sample-objects/shnum.x86_64");
|
||||
let io = std::fs::File::open(path).expect("Could not open file.");
|
||||
let mut file = ElfStream::<AnyEndian, _>::open_stream(io).expect("Open test1");
|
||||
|
||||
let (shdrs, strtab) = file
|
||||
.section_headers_with_strtab()
|
||||
.expect("shdrs should be parsable");
|
||||
|
||||
let shdrs_len = shdrs.len();
|
||||
assert_eq!(shdrs_len, 0xFF15);
|
||||
|
||||
let shdr = shdrs.get(shdrs_len - 1).unwrap();
|
||||
let name = strtab
|
||||
.get(shdr.sh_name as usize)
|
||||
.expect("Failed to get section name");
|
||||
|
||||
assert_eq!(name, ".shstrtab");
|
||||
assert_eq!(shdr.sh_type, abi::SHT_STRTAB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_header_by_name() {
|
||||
let path = std::path::PathBuf::from("sample-objects/basic.x86_64");
|
||||
|
Loading…
x
Reference in New Issue
Block a user