8 Commits
Author SHA1 Message Date
Maxime Mansiet f167f5a82f pe_loader: test a section and a relocation that start exactly at SizeOfHeaders
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 02:41:35 +01:00
Maxime Mansiet bac101ae8b pe_loader: refuse a section that overlaps the headers
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 01:42:59 +01:00
Ash Hopkins cc4799abdd runtime tests: synthetic fixed-base images take a base that is free under arm64 Wine
loader_test, test_pe_loader_bounds and unimplemented_policy_test build relocation-less images fixed at
0x140000000..0x1a0000000. Under arm64 Wine (CrossOver on Apple Silicon) the process's own allocations sit at
0x100000000 and up and macOS maps its shared region at 0x180000000 (RT-22), so the loader rejected those images
with "preferred base is taken" before the checks ran: loader stopped after 31 checks with 3 failures,
pe_loader_bounds failed 13 checks and unimplemented_policy failed.

New test/free_image_base.h: on Windows it returns the constants unchanged. Under Wine (ntdll exports
wine_get_version) it moves the whole 0x140000000..0x200000000 span to a free window picked top-down, away from
the heap, so each constant keeps its offset and images loaded together still get different bases. The init
image reads its TLS callback addresses from its own ImageBase instead of a constant.

AI-assisted. No game files.
2026-11-22 19:26:59 +00:00
totonii e49a735134 fix(pe_loader): validate SizeOfHeaders covers NT/section headers and guard truncated relocation blocks 2026-11-22 08:55:31 -03:00
quackottu 236b0acec3 pe_loader: honour NumberOfRvaAndSizes, and refuse a forwarder ordinal past 65535
Data directories past NumberOfRvaAndSizes were read anyway (only the
exception directory checked the count), so stale bytes there were parsed
as import, delay-import, export or relocation tables. And resolve_forwarder
range-checked the ordinal before adding each digit, so '#65537' passed and
was cast to ordinal 1. The hand-built test images now declare their 16
directories.
2026-11-22 12:48:35 +05:30
sanuk369 da3461826a test_pe_loader_bounds: a temp folder per process
Every image went to the fixed %TEMP%\leonida_pe_bounds_test, so two copies
running at once (two build trees, parallel CI jobs on one runner, several
ctest runs on one PC) overwrote each other's pe_bound_N.bin and deleted
the folder under each other at exit. The loser failed with "not an MZ
image", or case 4 loaded the other process's HIGHLOW image and saw a
delta that didn't fit. pe_loader_test and loader_tls_test already add the
process id; this does the same. LEONIDA_TEST_DIR still wins.
2026-11-22 11:12:36 +05:30
ismailchaka1 2b905ef651 Runtime: PE loader applies HIGHLOW (32-bit) base relocations
Loader::load threw "unsupported relocation type 3" on
IMAGE_REL_BASED_HIGHLOW, which the x64 Windows loader applies: 32-bit
absolute addresses, as /LARGEADDRESSAWARE:NO code has. They are now
moved by the delta like DIR64 ones. Where the moved address no longer
fits in 32 bits, Windows would truncate it; the loader refuses the image
with "a 32-bit (HIGHLOW) relocation does not fit at this base" instead.
Other 32-bit forms (HIGH, LOW, HIGHADJ) stay unsupported.

test_pe_loader_bounds.cpp was never built: it had no CMake target. It
now has one and runs under ctest as pe_loader_bounds (its existing 37
checks pass as they are). Five new checks build an image with a HIGHLOW
entry: the dword moves by exactly the delta, an address past 4 GiB is
refused, and HIGH is still rejected by name. Against the old loader,
three of them fail with "unsupported relocation type 3".
2026-11-22 02:37:52 +00:00
slopgobblercobbler 69d8741e1a test(runtime): add unit tests for PE loader boundary validation 2026-11-22 01:04:19 +01:00