Skip to content

Fix memory displacement overflowing i32 on AArch64 - #203

Merged
jiegec merged 2 commits into
capstone-rust:capstone-v6from
charleywright:capstone-v6
Aug 6, 2026
Merged

Fix memory displacement overflowing i32 on AArch64#203
jiegec merged 2 commits into
capstone-rust:capstone-v6from
charleywright:capstone-v6

Conversation

@charleywright

Copy link
Copy Markdown

For AArch64 instructions like 'LDR Xn, #imm' at addresses larger than i32::MAX the displacement overflows, producing an incorrect value. Fixed by returning i64 directly, as capstone does.

I ran into this with the following code:

__stubs:0000000100007324 50 1b 00 58         LDR     X16, #0x10000768C
__stubs:0000000100007328 00 02 1F D6         BR      X16

Without this change 0x10000768C overflows i32, giving a displacement of 0x768c.

I created a second branch for testing which adds an extra log in cstool - capstone-v6-test, that allows running this command:

cargo run --bin cstool -- --arch aarch64 --mode arm --detail --addr 100007324 --code "501b0058"
 100007324:  50 1b 00 58                         ldr     x16, 0x10000768c
             insn id:     634
             read regs:
             write regs:  x16
             insn groups:
offset: 0x10000768c

This matches the output of capstone's cstool:

./cstool -d aarch64 501b0058 0x100007324
100007324  50 1b 00 58  ldr	x16, 0x10000768c
	ID: 634 (ldr)
	op_count: 2
		operands[0].type: REG = x16
		operands[0].access: WRITE
		operands[1].type: MEM
		operands[1].mem.disp: 0x10000768c
		operands[1].access: READ
	Registers modified: x16

@jiegec jiegec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That is a copy-pasting error from master branch for capstone v5.

For AArch64 instructions like 'LDR Xn, #imm' at addresses larger than
i32::MAX the displacement overflows, producing an incorrect value.
Fixed by returning i64 directly, as capstone does.
@jiegec
jiegec merged commit bda1f4b into capstone-rust:capstone-v6 Aug 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants