fix(chansvm): avoid signed shift overflow in parsed index check #1022

Merged
coah80 merged 1 commits from agent/bittle/chansvm-index-width into main 2026-10-03 02:16:47 +00:00
coah80 commented 2026-10-03 02:15:32 +00:00 (Migrated from github.com)

Source-width correctness

In SET_INDEX's parsed-string path, compare the existing u64 directly against 0xFFFFFFFE instead of reconstructing it through a signed high-word shift and casting back to unsigned. Remove the now-unused reconstruction macro. Integer/float paths stay unchanged.

Original evidence

CHANSVmStep at 0x81456354 establishes the unsigned bound at +0x64/+0x68. Original DOL instructions at 0x81456E90–0x81456EB4 compare the parsed high/low words unsigned. CHANSVmParseInt uses strtoull; local MSL parsing negates in unsigned width, so negative strings can produce values with bit63 set. The old signed shift overflows for those values.

Independent parent verification

  • Reproduced baseline UBSan failure on parsed "-1"; extracted candidate passes 300028 parsing/unsigned-boundary cases
  • Re-executed the original-DOL comparison slice for 300010 values against a separate high/low-word oracle; error branch and accepted indices agree
  • Host parser harness uses an ASCII shim and host strtoull; local MSL negative-sign behavior was checked separately. These are bounded tests, not full VM/Wii execution
  • Entire compiler object byte-identical: SHA256 f971cabf817dba7e5cb240df01e1e8f814bb0a973e357a594d031046a56e691b
  • Complete 1027-unit report unchanged; 222/233 exact functions and data6904 preserved
  • Full43U all_source/report/progress/DOL and worktree/diff checks pass; prior pool125 and literal40 checks remain unchanged with identical object

No percentage gain or new exact function claimed. No header, configuration, metadata, compiler, linking or storage changes. Includes concise evidence log.

Base: a894ff5cb7
Tested tree: f9582a0a74
DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d

No merge performed or requested by this author.

Note

Fix signed shift overflow in CHANSVm parsed string index check

  • Removes the VM_S64_FROM_U64 macro, which rebuilt a 64-bit value via a signed high-word left shift
  • The SET_INDEX string path in CHANSVmStep now compares the unsigned value from CHANSVmParseInt directly against the existing unsigned bound, avoiding undefined behavior when bit 63 is set; integer and float index paths are unchanged
  • Adds an investigation log in CHANSVm-index-width-20261003.md with binary evidence and test measurements

Macroscope summarized a4b4c66.

## Source-width correctness In SET_INDEX's parsed-string path, compare the existing u64 directly against 0xFFFFFFFE instead of reconstructing it through a signed high-word shift and casting back to unsigned. Remove the now-unused reconstruction macro. Integer/float paths stay unchanged. ## Original evidence CHANSVmStep at 0x81456354 establishes the unsigned bound at +0x64/+0x68. Original DOL instructions at 0x81456E90–0x81456EB4 compare the parsed high/low words unsigned. CHANSVmParseInt uses strtoull; local MSL parsing negates in unsigned width, so negative strings can produce values with bit63 set. The old signed shift overflows for those values. ## Independent parent verification - Reproduced baseline UBSan failure on parsed "-1"; extracted candidate passes 300028 parsing/unsigned-boundary cases - Re-executed the original-DOL comparison slice for 300010 values against a separate high/low-word oracle; error branch and accepted indices agree - Host parser harness uses an ASCII shim and host strtoull; local MSL negative-sign behavior was checked separately. These are bounded tests, not full VM/Wii execution - Entire compiler object byte-identical: SHA256 f971cabf817dba7e5cb240df01e1e8f814bb0a973e357a594d031046a56e691b - Complete 1027-unit report unchanged; 222/233 exact functions and data6904 preserved - Full43U all_source/report/progress/DOL and worktree/diff checks pass; prior pool125 and literal40 checks remain unchanged with identical object No percentage gain or new exact function claimed. No header, configuration, metadata, compiler, linking or storage changes. Includes concise evidence log. Base: a894ff5cb76db05ef7cf425eb5b6a9e25343e460 Tested tree: f9582a0a74ef698fc25cbae2f8c261856b2689f4 DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d No merge performed or requested by this author. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Fix signed shift overflow in CHANSVm parsed string index check > - Removes the `VM_S64_FROM_U64` macro, which rebuilt a 64-bit value via a signed high-word left shift > - The `SET_INDEX` string path in `CHANSVmStep` now compares the unsigned value from `CHANSVmParseInt` directly against the existing unsigned bound, avoiding undefined behavior when bit 63 is set; integer and float index paths are unchanged > - Adds an investigation log in [CHANSVm-index-width-20261003.md](https://github.com/coah80/wii-ipl/pull/1022/files#diff-b070111e7ce1bb6deb774fb0ec20acdbe5af9cae7e7acaa169390e17f80d238a) with binary evidence and test measurements > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized a4b4c66.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-03 02:16:45 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.