loader: fix ClzeroLoop ModRM decoding, >=2 GiB skip, unaligned/empty bounds, and EFlags #407
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!407
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-407"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AscilCH on GitHub · 2026-11-25 00:25 UTC · original
AscilCH:fix/loader-clzero-loop-decode-and-emulation→main· +124 −22 · 2 files · 1 commits · openProblem
Five bugs in
ClzeroLoopdecoding and emulation (crates/victory-loader/src/console_insn_decode.rsandconsole_insn.rs):mod == 3 && rm == RAXcheck:decodechecked48/4C 39without verifying(modrm & 0xC7) == 0xC0(orreg_idx != 0), misdecodingcmp rcx, rdx(48 39 D1),cmp [rax], rdx(48 39 10), andcmp rax, rax(48 39 C0) asClzeroLoop.>= 2 GiB:if end > start && end - start < 2 << 30skipped zeroing entirely on runs>= 2 GiB, then still setctx.Rax = endand jumped past the 12-byte loop — silently leaving the buffer unzeroed.end <= start: Hardwareclzero; add rax, 0x40; cmp rax, end; jbis a bottom-tested loop that always executesclzeroat least once, whereasemulatezeroed nothing and overwrotectx.Rax = end.RAXon unalignedstartorend - start:write_bytes(start, 0, end - start)failed to clear[start & !63, start)and[end, aligned_end)and setRAX = endinstead ofstart + 64 * ceil((end - start)/64).EFlags: Skippingcmp rax, endleftEFlagsunchanged instead of updating arithmetic flags forrax == end.Fix
(code[i + 9] & 0xC7) == 0xC0andreg_idx != 0inconsole_insn_decode::decodebefore returningConsoleOnly::ClzeroLoop.console_insn::emulate, fall back to single-instructionclzero(line = start & !63,ctx.Rip += len - 9) wheneverstart & 63 != 0 || end <= start || (end - start) & 63 != 0so the CPU executesadd/cmp/jbnatively.< 2 << 30silent skip sowhile at < endwalks writable regions of any size viawritable_to.ctx.EFlags(ZF=1, PF=1, CF=AF=SF=OF=0) on fast-path completion.console_insn_decode::testsandconsole_insn::tests.Verification
cargo test -p victory-loader --locked: 25 unit + 3 integration passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-loader --all-targets --locked -- -D warnings: cleancargo clippy -p victory-loader --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.