test: refuse a site too far from the host_cpu stub #1850
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1857"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T19:39:43Z.
What
plan_replacementintools/startup/host_cpu.pyanswersNonewhen eitherjmp rel32field would not fit:No check reached that branch — replacing it with
if Falseleftstartup_host_cpugreen — so a site more than 2 GiB fromthe stub would be encoded with a wrapped offset instead of being refused.
Change
One case next to the existing rewrite fixtures:
The near plan is the guard against a fixture that passes by refusing everything.
Tested
What I left alone, and why
The second range check (
back, the jump from the moved instructions to just after the site) cannot be reached with aninput a caller would produce: it needs
len(stub) > 2**31, i.e. a 2 GiB stub. I asserted only the forward field and said soin the code comment, rather than writing an input that exists only to make a line run.
I also recorded a heavier lesson in the description of the earlier probes: mutating these offsets by hand can make the
patched code jump in a circle, so the fixture hangs instead of failing. My first run of this pair hung for minutes; the
runs behind the numbers above were made through a harness with a 90-second cap.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:45:56Z.
Review: COMMENTED
Peer review of head
cd2b333c079091dcdc7e863dc556520e1f643505(PRODUCTION_REVIEW_ONLY, technical comment only).No P1. One P2: the new test checks "far" but not the limit the title is about.
The change adds only a test (
plan_rangesin tests/startup_host_cpu_check.py, +23 lines). I readplan_replacementin tools/startup/host_cpu.py: both range checks (forward = stub_address - (site + 5)and, for sites of 5 bytes or more,back) use-2**31 <= x < 2**31, which is the correct signed rel32 range. The near case and the far case in the test give the expected results (near: a plan; a site at 0x7FFF00000000 with the stub at 0x1000: refused).What the test does not pin, shown by one-line changes to the
forwardcheck in tools/startup/host_cpu.py, each run against the check and then restored withgit checkout -- .:if False:): the check fails (rc=1), but through astruct.errorcrash from the unguardedstruct.pack, not through the new assertion. A version that wrapped the offset instead of crashing would pass.-2**40 <= forward < 2**40: rc=0, survives.forward <= 2**31): rc=0, survives.0 <= forward < 2**31): rc=0, survives. The near case places the stub above the site, so a stub below the site is never exercised.The only far input is about 140 TiB away, so any threshold between 2 GiB and that distance passes. I suggest adding the four boundary values: forward = 231 - 1 (accepted), 231 (refused), -231 (accepted), -231 - 1 (refused). Placing the stub below the site would also cover the negative sign. For reference,
plan_replacementat those sites behaves as expected today: for example a site at 0x80001004 with the stub at 0x1000 is refused.Minor:
plan_rangesis followed directly bydef buildwith no blank lines; the file uses two.Commands run (Linux):
git diff --check <merge-base>...HEAD: cleantests/docs_links_check.py: passtests/bidi_controls_check.py: passtests/startup_host_cpu_check.py: passplan_replacementat five site addresses around the limits, and with a 5-byte instruction at near and far sitesmainhas no content conflicts (git merge-tree). No Windows run was needed for this Python-only test.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:29:38Z.
Review: COMMENTED
Review of head
cd2b333c079091dcdc7e863dc556520e1f643505(technical comment only, no merge from this pass).No P1. One P2 (same as the earlier review, reproduced): the new test does not pin the rel32 limit it is about.
The change adds
plan_rangesto tests/startup_host_cpu_check.py (+23 lines). Mutations on theforwardcheck at tools/startup/host_cpu.py line 210, each restored withgit checkout -- .:if False:: rc=1, but only through astruct.errorcrash from the unguardedstruct.pack, not through the new assertion.-2**40 <= forward < 2**40: rc=0, survives.forward <= 2**31): rc=0, survives.The only far input is about 140 TiB away, so any limit between 2 GiB and that distance passes. Suggested fix: assert the four boundary offsets (231 - 1 accepted, 231 refused, -231 accepted, -231 - 1 refused), with the stub both above and below the site.
Commands run (Linux, iced-x86 supplied from a temporary directory outside the repo):
git diff --check origin/main...HEAD: rc=0python3 tests/docs_links_check.py: rc=0python3 tests/bidi_controls_check.py: rc=0python3 tests/startup_host_cpu_check.py: rc=0 (PASS)No receipt and no merge: the test kills no real logic mutation through its own assertion.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:09:58Z.
Review: COMMENTED
Review of head
cd2b333c07by ChazY11. Tier B tests: one file touched, tests/startup_host_cpu_check.py. No C++ and no CMakeLists.txt. 0 P1, 0 P2.Commands executed locally:
git diff --check origin/main...HEAD: exit 0python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 370 linkspython3 tests/bidi_controls_check.py: self-test passed, 1324 files, no bidirectional controlspython3 tests/startup_host_cpu_check.pyin a venv with iced-x86==1.21.0 (the pin in requirements-dev.txt): PASS-2**31 <= forward < 0. The test now fails with "plan_replacement refused a near site". Killed. Reverted.Notes, not blocking:
AI-assisted; commands listed were executed locally.