Skip to content

[AUTOMATED] find_subpiece_shadow: read a truncation past bit 63 of a constant as 0 instead of overflowing - #1683

Merged
mahaloz merged 3 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/subpiece-shadow-shift
Nov 19, 2026
Merged

mahaloz merged 3 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/subpiece-shadow-shift

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

[AUTOMATED]

The problem

In a build with integer-overflow checks (the dev and test profiles), _dl_relocate_object from the in-repo mcount_x86_64 fixture comes back as an empty body. It is the only one of the fixture's 1074 functions that fails.

$ cd decompiler && cargo build -p kuna-cli -p kuna-console -p kuna-slacomp && cd ..
$ decompiler/target/debug/slacomp -a specs
$ decompiler/target/debug/kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/mcount_x86_64 _dl_relocate_object
void _dl_relocate_object(void)
{
  /* WARNING: decompilation failed: decompile pipeline reached an un-ported seam (LOSS-131): attempt to shift right with overflow */
}
thread 'main' panicked at crates/kuna-decomp/src/substrate/funcdata.rs:4901:27:
attempt to shift right with overflow

The function zeroes a 16-byte stack slot (pxor xmm0,xmm0; movaps [rbp-0x70],xmm0) and later writes the slot's high quadword from rsi, which is 0 on one path. The merge intersection test then asks whether the 8-byte constant 0 is a partial copy shadow of the 16-byte constant 0 at byte offset 8.

The fix

  • Funcdata::find_subpiece_shadow shifted the constant's 64-bit offset right by least_byte * 8, which is 64 or more for a truncation of 8 or more bytes. The C++ original (Varnode::findSubpieceShadow) has the same shift, undefined there.
  • A constant wider than 8 bytes holds zero above bit 63, so such a truncation now reads 0. Shifts below 64 are unchanged.
  • No option: the old code either panicked or, without overflow checks, shifted by a wrapped count.

With the fix _dl_relocate_object decompiles to a 980-line body in about 1.6 s (dev build). On this function and on the new test, a build that wraps the shift count prints the same text as the fixed one, so builds without overflow checks show no output change here.

The tests

  • tests/stages/gh1674-subpiece-shadow-wide-const.xml: a 28-instruction reduction of the same shape. Without the fix all 4 assertions fail in a dev build; with it all pass.
  • Datatest corpus 675/675; no existing stage expectation moved.

Fixes #1674

coleleavitt and others added 2 commits November 18, 2026 16:48
…r more bytes

Funcdata::find_subpiece_shadow shifted a constant's 64-bit offset right by least_byte * 8. For a 16-byte constant tested at byte offset 8 that is a shift by 64: a panic in a build with overflow checks, a wrapped shift count otherwise. _dl_relocate_object in the mcount_x86_64 fixture failed to decompile in a dev build because of it.

A constant wider than 8 bytes holds zero above bit 63, so the truncation now reads 0 there. Shifts below 64 are unchanged.

Fixes Noelo-Lab#1674
…d profile

The gh1674 stage test only fails without the fix in a build with overflow
checks: a release build wraps the shift count, and for the constant 0 the
wrapped shift reads the same 0. The unit test calls
varnode_partial_copy_shadow on 16-byte constants directly, so it fails
on the unfixed code under the test profile (the overflow panic) and also
with a wrapping shift (an 8-byte piece at offset 8 of the 16-byte
constant 0x1234 is not 0x1234).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed 7a8d712 on top of your branch: it adds the unit test partial_copy_shadow_reads_zero_above_bit_63_of_a_wide_constant in substrate/funcdata.rs. The gh1674 stage test only fails without the fix when overflow checks are on. make test-stages runs a release build, where the wrapped shift reads the same 0 for the constant 0, so the stage test passes there with or without the fix. The unit test calls varnode_partial_copy_shadow on 16-byte constants directly. On the old code it fails under the test profile with the overflow panic, and it also fails with a wrapping shift, because an 8-byte 0x1234 at offset 8 of the 16-byte constant 0x1234 is not a shadow. The fix itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h

# Conflicts:
#	decompiler/crates/kuna-base/src/xml.rs
#	docs/baseline-stages.json
@mahaloz
mahaloz merged commit b779fcf into Noelo-Lab:main Nov 19, 2026
2 checks passed
@coleleavitt
coleleavitt deleted the fix/subpiece-shadow-shift branch November 21, 2026 06:26
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.

[AUTOMATED] find_subpiece_shadow panics with a shift-right overflow on a wide constant (dev build, mcount_x86_64 _dl_relocate_object)

2 participants