mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:35:53 +01:00
[PR #2041] runtime: guard base_reservation parsing and VirtualQuery loop overflow #2048
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2048
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2041
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-base-reservation-overflow-and-parse-guards📝 Commits (1)
2e8a92druntime: guard base_reservation parsing and VirtualQuery loop overflow📊 Changes
2 files changed (+48 additions, -9 deletions)
View changed files
📝
runtime/src/base_reservation.h(+42 -9)📝
runtime/test/pe_loader_test.cpp(+6 -0)📄 Description
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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.