test(allocator): check pe_import_first's malformed images in memory #14134
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14134"
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 boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-31T20:25:09Z.
What
pe_import_first(TIMEOUT 10,core/libs/CMakeLists.txt:389) timed out without output from time to time on Windows 11 with Microsoft Defender's real-time and cloud protection at their defaults. Each failure case wrote its image to%TEMP%and passed it toMoveImportFirstInFile, and that call stalled on the freshly written copy ofoptional-header-incomplete-import-entry(SizeOfOptionalHeader127, added in #11356). A probe that wrote fresh copies of the test's images (8 changed bytes in the DOS header) and timedMoveImportFirstInFilemeasured 296.8 to 10062.0 ms for that image in 24 runs, 6 of them over 1 s and 2 at about 10.06 s; every other image the test wrote took at most 43.9 ms, and the same image withMZreplaced byXXtook 8.7 to 18.7 ms. That points to Defender's check of an unknown PE-shaped file; the cause is inferred from these timings, not observed. A run that hits a long stall exceeds the test's 10 s limit. The test passes on the project's Windows runners in 0.03 s.The failure cases do not need the file. Every throw in
MoveImportFirst(PeImportFirst.cpp:40-85, including the bounds checks inread16andread32) comes before its only write to the image (line 87), andMoveImportFirstInFileopens the file for writing only afterMoveImportFirstreturns (lines 97-99). The eight malformed-image cases (truncated-directory,pe32,directory-count-zero,directory-count-one,optional-header-without-imports,optional-header-incomplete-import-entry,unterminated-name,name-past-the-file) now runMoveImportFirston a copy of the bytes and require the same error text and an unchanged copy, which also checks thatMoveImportFirstleaves the bytes alone when it throws; the file round trip could not see that, because the file is only written after a successful move.missing-importstays on disk and keeps covering the unchanged-file path, and the two file moves are unchanged. The names, expected texts and order of the cases are unchanged.TIMEOUT 10stays, since CONTRIBUTING.md asks to shrink a test that gets close instead of raising its timeout.pr_overlap.py --branchreports no overlap with open pull requests.Tested
Windows 11 Home (build 26200), Intel Core i9-12900H, WinLibs GCC 15.2.0, full build (Ninja, Release,
BUILD_TESTING=ON), on2f7381f9ea(based on474030e584):pe_import_firsttimed out in a fullctest --test-dir build -j 6on73f4f7e06eand again in a serial rerun.ctest --test-dir build -R '^pe_import_first$'passed three times in 0.03 to 0.11 s.optional-header-incomplete-import-entrytook 296.8 to 10062.0 ms (24 runs with fresh bytes) and the other seven malformed images at most 42.8 ms (12 runs each with fresh bytes); the three files it writes now (two-directory,moved,missing-import) took 13.3 to 43.9 ms (12 runs each with fresh bytes).optional-header-incomplete-import-entryand one with a valid PE32+ image forpe32, fail withfailed with another error: the image has no importsandthe move did not fail.python tools/check_conventions.py --base 474030e584with this title and description passed on2f7381f9ea.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T20:36:51Z.
Review: APPROVED
Reviewed — looks good
The in-memory failure cases check that malformed images remain unchanged, while successful and missing-import file-path cases remain covered.
What I ran
Reviewed head
2f7381f9ea4f258e12415cce50c54d7d08b7062bagainst base0836dfdf4fecb1e0326100c490476e15d3a74da5; the stack helper's merge preview was clean. Environment: Debian Linux, GCC 12.2.0.Results
pe_import_firstbuild and testConventions check output
Merge preview output
Findings
Blocking
None found in the test-only diff.
Non-blocking
The malformed-image cases no longer exercise the file wrapper, but the unchanged-file case for a missing import and both successful file operations remain. In the reviewed implementation, the file wrapper opens the output only after the in-memory operation returns successfully.
Sources
Not verified
I did not build or run the C++ test locally. The Windows workflow did not run this allocator test; the full build, repeated CTest runs, and scratch negative controls above are author-reported evidence.