startup: reject a writable range whose size wraps the address space #1517

Merged
RenzoWit35 merged 1 commit from upstream-pr/1524 into main 2026-11-24 14:26:09 +00:00
RenzoWit35 commented 2026-11-24 13:37:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:37:50Z.


Change

x2w_local::accessible in src/startup_stubs/local_log.h (behind readable and writable) checked the write path with start + bytes > end, where end is the end of the region VirtualQuery returned. For a size near SIZE_MAX the sum wraps below end, so the check passed and writable(p, SIZE_MAX - 8) returned true for something that is not a range. No earlier guard catches it: only a start below 0x10000, a start above the user limit and a zero size are rejected.

The read path was not affected. probe_readable computes its own end = start + bytes, which wraps too, so its loop does not run and it reports zero bytes.

The comparison is now bytes > end - start. start lies inside the queried region, so that difference cannot wrap. Nothing else in the header changes.

This builds on the test added in #1477: tests/startup_local_log_check.cpp gains three wrapping-size checks next to its other boundary cases. No new test target.

Verification

Windows 11, MSVC 14.51.36231, cmake --preset dev, base origin/main 60c72330.

cmake --build out/build/dev --target startup_local_log_check
ctest --test-dir out/build/dev --no-tests=error -R '^startup_local_log' --timeout 120

Negative control, with local_log.h from main and the three new checks:

FAIL accessible rejects a size that wraps start + bytes (GetLastError=0)
FAIL writable rejects SIZE_MAX bytes (GetLastError=0)
FAIL writable rejects a wrapping size from inside the region (GetLastError=0)
startup_local_log: 3 of 78 FAILED

With the fix: startup_local_log Passed and startup_local_log_guard_drop_control Passed (2/2).

Not run: the other startup tests, GPU tests and the full suite. I did not search for a caller that passes such a size today; the change makes the helper's answer correct for any size.

Evidence and follow-up

The inputs are sizes computed in the test against pages it allocates itself; no external data.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583044780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1524). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T13:37:50Z. --- ## Change `x2w_local::accessible` in `src/startup_stubs/local_log.h` (behind `readable` and `writable`) checked the write path with `start + bytes > end`, where `end` is the end of the region `VirtualQuery` returned. For a size near `SIZE_MAX` the sum wraps below `end`, so the check passed and `writable(p, SIZE_MAX - 8)` returned true for something that is not a range. No earlier guard catches it: only a start below 0x10000, a start above the user limit and a zero size are rejected. The read path was not affected. `probe_readable` computes its own `end = start + bytes`, which wraps too, so its loop does not run and it reports zero bytes. The comparison is now `bytes > end - start`. `start` lies inside the queried region, so that difference cannot wrap. Nothing else in the header changes. This builds on the test added in #1477: `tests/startup_local_log_check.cpp` gains three wrapping-size checks next to its other boundary cases. No new test target. ## Verification Windows 11, MSVC 14.51.36231, `cmake --preset dev`, base `origin/main` 60c72330. ``` cmake --build out/build/dev --target startup_local_log_check ctest --test-dir out/build/dev --no-tests=error -R '^startup_local_log' --timeout 120 ``` Negative control, with `local_log.h` from `main` and the three new checks: ``` FAIL accessible rejects a size that wraps start + bytes (GetLastError=0) FAIL writable rejects SIZE_MAX bytes (GetLastError=0) FAIL writable rejects a wrapping size from inside the region (GetLastError=0) startup_local_log: 3 of 78 FAILED ``` With the fix: `startup_local_log` Passed and `startup_local_log_guard_drop_control` Passed (2/2). Not run: the other startup tests, GPU tests and the full suite. I did not search for a caller that passes such a size today; the change makes the helper's answer correct for any size. ## Evidence and follow-up The inputs are sizes computed in the test against pages it allocates itself; no external data. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:01:50 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1517
No description provided.