From cd7c0ee4d4ee98fa131ccba9dfe942900071e437 Mon Sep 17 00:00:00 2001 From: Aetias Date: Thu, 20 Nov 2025 23:20:53 +0100 Subject: [PATCH] arm: Fix .word reading 4 bytes when less than 4 remain --- objdiff-core/src/arch/arm.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index 2640ae8..66aa157 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -224,12 +224,14 @@ impl Arch for ArchArm { } // Check how many bytes we can/should read - let num_code_bytes = if mode == unarm::ParseMode::Data { - // 32-bit .word value should be aligned on a 4-byte boundary, otherwise use .hword - if address & 3 == 0 { 4 } else { 2 } - } else if data.len() >= 4 { - // Read 4 bytes even for Thumb, as the parser will determine if it's a 2 or 4 byte instruction - 4 + let num_code_bytes = if data.len() >= 4 { + if mode == unarm::ParseMode::Data && address & 3 != 0 { + // 32-bit .word value should be aligned on a 4-byte boundary, otherwise use .hword + 2 + } else { + // Read 4 bytes even for Thumb, as the parser will determine if it's a 2 or 4 byte instruction + 4 + } } else if mode != unarm::ParseMode::Arm { 2 } else {