Skip to content

[AUTOMATED] fix(analysis): Rust v0 detection requires the leading underscore - #332

Merged
mahaloz merged 1 commit into
mainfrom
fix/rust-mangle-prefix
Aug 22, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/rust-mangle-prefix

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

The defect

is_rust_mangled's v0 arm intends to match Rust v0 mangling (_R…):

let v0 = name.strip_prefix('_').unwrap_or(name);
if v0.starts_with('R') && v0.len() > 1 { return true; }

strip_prefix returns None when there is no leading underscore, and .unwrap_or(name) then hands back the original name — so the test silently degenerates from "begins with _R" to "begins with R".

symbols_indicate_rust is an .any(), so one matching symbol classifies the whole image. OpenSSL's RAND_bytes, RSA_new, RAND_add all match.

What it costs the reader

Via DIV-80's --language auto policy, ordinary C programs render as Rust:

$ readelf -p .comment /usr/bin/ncat | grep GCC
  GCC: (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

$ kuna decompile /usr/bin/ncat --addr 0x1e640          # before
unsafe fn sub_1e640(mut a0: u64, mut a1: u32) -> *mut u64

$ kuna decompile /usr/bin/ncat --addr 0x1e640          # after
unsigned long * sub_1e640(unsigned long a0,unsigned int a1)

A real Rust binary is unaffected — private/FakeCrypt still detects as Rust and renders unsafe fn encrypt_file(…).

The misclassification also reaches anything else gated on Compiler::Rustc (the Rust no-return list, noreturn_propagate's widening).

Why no test caught it

Every fixture in both parity corpora is a <bytechunk> image with no symbol table, so symbols_indicate_rust is never reached. The corpora are structurally blind to this predicate. The new regression test pins the OpenSSL names directly.

Provenance, stated plainly

Found by an adversarial verifier reviewing the rustabi gate (PR #331), not by the implementer. The implementer's C-collateral sweep — grep, sort, faillog, libselinux.so.1, fauxware — reported zero differences and was correct: all five carry zero R-prefixed symbols. Sample bias, not carelessness. PR #331 is held until this lands, because its Rust gate is only sound afterwards.

Gates

Gate Result
make test PARITY OK 675/675
make test-stages PARITY OK
make rust-test exit 0, 319 groups
make check-spec OK lenient and --strict
kuna catalog --check OK

No option, no catalog change, no baseline re-pin — this is a strict bug fix that only corrects wrong output. Spec prose added to docs/spec/01-program-prep.md beside the demangler-routing paragraph.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WUuE4zdiEqZFWLL2YEUk9

…erscore

`is_rust_mangled`'s v0 arm was written

    let v0 = name.strip_prefix('_').unwrap_or(name);
    if v0.starts_with('R') && v0.len() > 1 { return true; }

and `strip_prefix` returns None when there is no leading underscore, so
`.unwrap_or(name)` hands back the ORIGINAL name and the test degenerates from
"begins with `_R`" to "begins with `R`". One matching symbol classifies the whole
image, so any C program importing OpenSSL's `RAND_bytes` / `RSA_new` / `RAND_add`
was reported as `Compiler::Rustc`.

That reaches the reader through DIV-80's `--language auto` policy:

    $ kuna decompile /usr/bin/ncat --addr 0x1e640      # ncat is C
    unsafe fn sub_1e640(mut a0: u64, mut a1: u32) -> *mut u64

After the fix ncat renders as C and a real Rust binary still renders as Rust.

Neither parity corpus can see this: every datatest and stage fixture is a
`<bytechunk>` image with no symbol table, so `symbols_indicate_rust` is never
consulted. The regression test pins the OpenSSL names directly.

Found by an adversarial verifier while reviewing the `rustabi` gate. The
implementing agent's own C-collateral sweep (grep, sort, faillog,
libselinux.so.1, fauxware) reported zero differences and was correct -- all five
carry zero `R`-prefixed symbols. Sample bias, not carelessness.

Gates: make test 675/675 PARITY OK; make test-stages PARITY OK; make rust-test
exit 0 (319 groups); make check-spec OK lenient + strict; catalog --check OK.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016WUuE4zdiEqZFWLL2YEUk9
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.

1 participant