Skip to content

Undefined behavior #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
umanwizard opened this issue May 19, 2025 · 2 comments · May be fixed by #178
Open

Undefined behavior #175

umanwizard opened this issue May 19, 2025 · 2 comments · May be fixed by #178

Comments

@umanwizard
Copy link

umanwizard commented May 19, 2025

This test segfaults reliably on v0.13.0:

#[cfg(test)]
mod tests {
    use capstone::Capstone;
    use capstone::arch::{BuildsCapstone, DetailsArchInsn};

    #[test]
    fn capstone_segfaults() {
        let cs = Capstone::new()
            .arm64()
            .detail(true)
            .mode(capstone::arch::arm64::ArchMode::Arm)
            .build()
            .unwrap();

        let insns = cs.disasm_all(&[0x0c, 0x44, 0x3b, 0xd5], 0).unwrap();
        for i in insns.as_ref() {
            let id = cs.insn_detail(&i).unwrap();
            let ad = id.arch_detail();
            let aarch = ad.arm64().unwrap();

            println!("{i} (dt: {:?})", aarch.operands().collect::<Vec<_>>());
        }
    }
}
@umanwizard
Copy link
Author

This seems to be caused by capstone-engine/capstone#1881

The second operand of this instruction is coming through as type Sys but its value is not one of the variants of Arm64SysOp. And unsafely creating a value whose discriminant is not one of the valid discriminants of the enum type is UB (which manifests here by crashing when we try to print it out).

@jiegec
Copy link
Contributor

jiegec commented May 23, 2025

The upstream fixes it in the next branch, but we will need to wait for capstone v6 then. You can try the WIP branch at https://github.com/capstone-rust/capstone-rs/tree/capstone-v6.

@jiegec jiegec linked a pull request May 24, 2025 that will close this issue
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 a pull request may close this issue.

2 participants