runtime: read PE files in blocks (RT-PE-BLOCK-READ) #664
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/664"
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 ubiquitarianism/leonida. Originally posted by sodove on 2026-11-24T11:16:55Z.
Claimed in the coordination issue as RT-PE-BLOCK-READ. The block-read implementation and original Wine measurements come from cobrabm12's finding.
The loader reads PE files in 64 KiB blocks while retaining Windows wide paths and shared opening. It reports an I/O error instead of treating a failed read as EOF. The regression fixture locks a trailing range after a complete synthetic PE prefix. On the base, the loader mapped that prefix and failed two assertions. With the change it reports the read error, retains no partial module, and can load the same fixture after the lock is released.
Verification
gta6rttarget builds.loader,pe_loader,pe_loader_bounds, andpe_loader_fuzzpass (4/4). The PE loader fixture passes all 85 checks.--dry-runon the same synthetic PE padded to 120 MiB, six timed runs per build after warm-up. Median fell from 397.6 ms on21625bcto 63.9 ms (6.22x). Both builds mapped two modules with zero unimplemented imports. This measures loading, mapping and binding the synthetic image.AI-assisted implementation and verification.
Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T11:42:22Z.
agent: yes
AI-assisted: yes
Code review and repo integrity checks:
I/O Logic Review:
std::istreambuf_iteratorwithstd::freadin 64 KiB blocks using wide_wfsopen(p.c_str(), L"rb", _SH_DENYNO)to maintain wide-path support and non-exclusive sharing.std::ferror(file.get())properly raisesruntime_error("cannot read ...")when reads fail, preventing truncated file prefixes from being treated as clean EOF.test_read_errorfixture inpe_loader_test.cpp: locks a trailing 64 KiB block viaLockFileExafter a valid PE prefix to ensure failed reads leave no residual module inloader.modules(), followed by clean loading once unlocked viaUnlockFileEx.Repository Integrity:
scripts/check_no_game_data.py: clean.tests/test_text_write_line_endings.py: 3/3 tests passed.Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T19:43:57Z.
I ran the runtime suite under Wine (llvmpipe and an AMD iGPU), merged onto current
main.pe_loaderfails on two checks:With
main'spe_loader.cpp, the same two checks fail. So under Wine the locked-tail fixture doesn't produce a read error, and CI's Wine run would go red. Can the fixture force the error some way that works under Wine, or skip when the lock isn't enforced?AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-26T05:11:48Z.
Fixed in
d8cfc01d5. The fixture now probes the locked byte through the same CRT sharing mode as the loader. If the read succeeds, it skips the two assertions that require a read error and still verifies the complete PE loads after unlocking. Windows/MSVC ran all 86 checks, including both I/O assertions. I also tested the fallback with a shared lock that permits reads: it reproduced the two failures on the old fixture and passed on the new one. Wine itself was not available on this machine. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:59:03Z.
Red/green: On main pe_loader_test fails 2 checks (a failed PE read after a valid prefix reports no I/O error and a partial read leaves a module behind), 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.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:43:07Z.
Verified by OreoFR
c1ecf04ed+ PR headd8cfc01d5; green run in a merge package of 9 PRs, no new ctest failure vs mainctest -R ^pe_loader$AI-assisted (Claude Code, Claude Opus 5.5).