Skip to content

Commit 2ff6adb

Browse files
committed
Fix ARM panic when a code section has no mapping symbols
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
1 parent 2cd1e2e commit 2ff6adb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

objdiff-core/src/arch/arm.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl Arch for ArchArm {
184184
.disasm_modes
185185
.get(&section_index)
186186
.map(|x| x.as_slice())
187+
.filter(|x| !x.is_empty())
187188
.unwrap_or(&fallback_mappings);
188189
let first_mapping_idx = mapping_symbols
189190
.binary_search_by_key(&start_addr, |x| x.address)
@@ -631,3 +632,28 @@ impl unarm::FormatIns for ArgsFormatter<'_> {
631632
Ok(())
632633
}
633634
}
635+
636+
#[cfg(test)]
637+
mod tests {
638+
use alloc::collections::BTreeMap;
639+
640+
use super::*;
641+
642+
#[test]
643+
fn scan_instructions_empty_mapping_symbols() {
644+
// A code section that has an entry in disasm_modes but no mapping symbols
645+
// (e.g. an ELF whose .text has no $a/$t/$d symbol) should fall back to ARM
646+
// mode instead of indexing an empty slice and panicking.
647+
let mut disasm_modes = BTreeMap::new();
648+
disasm_modes.insert(0, Vec::new());
649+
let arch = ArchArm {
650+
disasm_modes,
651+
detected_version: None,
652+
endianness: object::Endianness::Little,
653+
};
654+
let code = [0x00, 0x00, 0xa0, 0xe1]; // mov r0, r0
655+
let refs =
656+
arch.scan_instructions_internal(0, &code, 0, &[], &DiffObjConfig::default()).unwrap();
657+
assert_eq!(refs.len(), 1);
658+
}
659+
}

0 commit comments

Comments
 (0)