runtime: guard base_reservation parsing and VirtualQuery loop overflow #2041
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2041
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/rt-base-reservation-overflow-and-parse-guards"
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?
Pull request successfully merged and closed
Coordination item:
RT-BASE-RESERVATION-OVERFLOW-AND-PARSE-GUARDS(claimed on #1608).Why
runtime/src/base_reservation.h(used on macOS CrossOver / arm64 Wine FEX to keep a relocation-less PE image's preferred base free) had several edge-case parsing and arithmetic bugs:needed()looped withfor (uint64_t at = r.base; at < r.base + r.size;)and steppedat = info.BaseAddress + info.RegionSize. Ifr.base + r.sizewrapped 64-bit address space, the loop skipped immediately; ifinfo.RegionSize == 0orBaseAddress + RegionSizewrapped aroundUINT64_MAX,atfailed to advance and looped infinitely.inherited()usedswscanf_s(value, L"%llx:%llx", ...)which accepted trailing garbage ("140000000:30000000junk"), wrapped >64-bit hex digits, and accepted ranges wherebase + sizewrapped 64 bits.commit_reserved()did not rejectsize == 0orbase + sizewraparound before querying/committing.Changes
runtime/src/base_reservation.h:parse_range(const wchar_t*)that parses<hex>:<hex>with exact full-string match, overflow-checked hex accumulation, non-zero size, andbase <= UINT64_MAX - size.size == 0andbase > UINT64_MAX - sizeincommit_reserved().info.RegionSizeinneeded()soatstrictly advances and never wraps or infinite-loops.runtime/test/pe_loader_test.cpp: expandtest_inherited_reservation()to verify rejection of trailing garbage,base + sizewraparound, and >64-bit hex overflow.Verification
VirtualQuery/env stubs; Windows CI runs fullpe_loader_test).base_reservation.htest harness (including synthetic PE32+ files, multi-region free walk, pathologicalRegionSize == 0non-infinite-loop test, and wrappingImageBase) withclang++ -std=c++20 -Wall -Wextra -Werror:-O1 -g -fsanitize=address,undefined):base_reservation_harness: OK (0 fails).-O1 -g -fsanitize=thread):base_reservation_harness: OK (0 fails).-O2):base_reservation_harness: OK (0 fails).python3 -I scripts/check_no_game_data.py runtime/src/base_reservation.h runtime/test/pe_loader_test.cpp: clean.python3 -I tests/test_text_write_line_endings.py: 3/3 OK.Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmaind48a957bb+2e8a92d72a(claim#2570#issuecomment-7239583640):runtime/src/base_reservation.h,runtime/test/pe_loader_test.cpp); replacesswscanf_sinLEONIDA_BASE_RESERVEDparsing with an exact hex parser (parse_range) that rejects trailing characters, zero sizes, >64-bit hex overflow, andbase + size64-bit wraparound, and bounds theVirtualQuerywalk inneeded()against region/address-space wraparound.check_no_game_data.pyclean.d48a957bb+ PR test): Fullpe_loader_test.exe(tiny_dll.dll,tiny_exe.exe,gta6rt_tls_host.dll) fails (rc=1,pe_loader_test: FAILED (82 checks, 3 failures)on trailing junk,base + sizewraparound, and overflowing 64-bit hex base).d48a957bb+2e8a92d72amerge): Auto-merges cleanly (rc=0), compilesbase_reservation.h/pe_loader_test.cppwith0warnings under/W4 /permissive-, and passes (pe_loader_test: OK (82 checks),rc=0).AI-assisted.
Red/green: On main pe_loader_test fails 3 of 82 checks (LEONIDA_BASE_RESERVED with a trailing suffix, a 64-bit base+size overflow and an oversized hex base are accepted), and with the PR ctest -R "^pe_loader$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
Verified by OreoFR
c1ecf04ed+ PR head2e8a92d72; green run in a merge package of 16 PRs, no new ctest failure vs mainctest -R ^pe_loader$AI-assisted (Claude Code, Claude Opus 5.5).