Repository navigation
s8 structure: reject compound-head while-do fold under regionlooprefine (fix invalid C) - #145
Merged
Merged
Conversation
…ne (fix invalid C)
A fresh ghidra-beats-kuna case (libedit vi_history_word, O0) where kuna emits INVALID C: a
full nested loop WITH ITS BODY inside the outer loop's controlling expression —
`while ( while(v3=*v7, iswspace(v3)!=0){v7=&v7[1]} *v7!=0 ) {...}` — a statement-in-condition
C syntax error. It is brace-BALANCED, so neither naive nor literal-aware brace counting flags
it; only structural inspection does. Ghidra renders the clean `while(true){ inner-while;
if(*p==0) break; ...; if(cond) break; }`.
Root cause: regionlooprefine (S8, region_structurer.rs, default-on DIV-12 port of angr
RegionIdentifier._refine_loop_successors_to_guarded_successors) refines the outer loop into a
top-tested while-do candidate whose HEAD has absorbed the inner skip-whitespace loop (head
type = BlockList). try_fold_loop's while-do branch guarded against interior goto targets but
not against a compound (loop/if-containing) head, so the emitter renders that compound head
inside the outer `while(...)` condition under COMMA_SEPARATE. Confirmed culprit:
`--option regionlooprefine off` restores valid Ghidra-matching C.
Fix (23 lines, gated on loop_refine): a valid while-do head is always a single condition
block — BlockCopy (comma-expr basic block) or a folded BlockCondition (&&/||). Reject anything
else (BlockList/absorbed loop) so the loop folds as BlockInfLoop -> `while(true){...break}`, the
OFF/Ghidra form. Gated on loop_refine, so the base structurer that produces the 675
byte-identical datatests is completely untouched.
Verification: make test 675/675 PARITY OK, make test-stages 254/254, make rust-test 0 failures.
Whole-binary safety (libedit.so, 777 fns, true #142 baseline): SURGICAL — vi_history_word's
bad loop -> valid while(true) (while(true) 38->39), total gotos unchanged (105), 0
newly-unbalanced, 0 indent corruption; bzip2 (144 gotos) completely unchanged. Note: a
separate regionstructure compound-head case (bzip2 generateMTFValues) is NOT covered by this
loop_refine guard and remains for follow-up.
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018DV2MXxQAAWK7xLPBmsq9J
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A fresh ghidra-beats-kuna case (from the post-#6 fair re-run's current gap pool): libedit
vi_history_word(O0), kuna GED 60 vs Ghidra 9. kuna emits INVALID C — a full nested loop with its body inside the outer loop's controlling expression:It is brace-balanced, so neither naive nor literal-aware brace counting flags it — only structural inspection does (FINDING 3 in reverse: not every invalid-C bug is a brace imbalance). Ghidra renders the clean
while(true){ inner-while; if(*p==0) break; …; if(cond) break; }.Root cause
regionlooprefine(S8,region_structurer.rs, default-on DIV-12 port of angrRegionIdentifier._refine_loop_successors_to_guarded_successors) refines the outer loop into a top-tested while-do candidate whose head has absorbed the inner skip-whitespace loop (head typeBlockList).try_fold_loop's while-do branch guarded against interior goto targets but not against a compound (loop/if-containing) head, so the emitter renders that compound head inside the outerwhile(...)condition. Confirmed culprit:--option regionlooprefine offrestores valid, Ghidra-matching C.Fix (23 lines, gated on
loop_refine)A valid while-do head is always a single condition block —
BlockCopy(comma-expr basic block) or a foldedBlockCondition(&&/||). Reject anything else so the loop folds asBlockInfLoop→while(true){…break}. Gated onloop_refine, so the base structurer (which produces the 675 byte-identical datatests, and to whichregionlooprefineON is byte-identical on reducible code) is completely untouched.Verification
make test675/675 PARITY OK,make test-stages254/254,make rust-test0 failures.}invalid C + cross-function indent leak) #142 baseline): SURGICAL — vi_history_word's bad loop → validwhile(true)(while(true) 38→39), total gotos unchanged (105), 0 newly-unbalanced, 0 indent corruption; bzip2 completely unchanged.Note
A separate
regionstructurecompound-head case (bzip2generateMTFValues) is not covered by thisloop_refineguard and remains for follow-up. Related to (but distinct from) #143 (regionstructure complex-head overflow syntax) — both are while-do invalid-C fixes in the same branch; may need a trivial rebase if merged together.🤖 Generated with Claude Code
https://claude.ai/code/session_018DV2MXxQAAWK7xLPBmsq9J