fix(allocator): reject malformed import metadata in PeImportFirst #11356
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11356"
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 brainiac91 on 2026-10-26T08:06:19Z.
What
Fixes #11286. Reject malformed PE32+ import metadata before any in-place descriptor update while preserving valid minimal optional headers.
NumberOfRvaAndSizes >= 2) and its complete eight-byte entry at optional-header offsets 120–127. A valid 128-byte optional header with exactly two directories is accepted; a 127-byte header is rejected.Tested
-std=c++20 -O2 -Wall -Wextra -Werror; the resulting executable passes.the image has no imports, then passes with the eight-byte bound. The 127-byte-header case and all existing malformed-input checks reject without modifying their files.mainatf616a1397f9b618036ac7c89f461f0bd46fbd6d6. Neither affected file changed upstream between the original base and that commit.cmake --build build-tests --target pe_import_first_tests pe_import_firstsucceeds in the full-build configuration with bundled dependencies, andctest --test-dir build-tests -R '^pe_import_first$' -Vpasses 1/1.mimalloc.dll, movingmimalloc-redirect.dllahead ofADVAPI32.dllandKERNEL32.dll. An independent PE parser verifies whole-descriptor rotation, stable remaining order, byte-for-byte preservation outside the descriptors, and no further change on a second run; the source DLL is unchanged.tools/pr_overlap.py --branch fix/pe-import-malformed-metadata --repo boykopovar/AnyPS5completes with only PR #11356 itself reported before the rebased branch is pushed; no other PR overlaps.tools/check_conventions.py --base origin/mainandgit diff --check origin/main...HEADpass.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-26T08:41:02Z.
Review: CHANGES_REQUESTED
I independently built the exact PR sources (
PeImportFirst.cppandPeImportFirstTests.cpp) withg++ -std=c++20 -Wall -Wextra -Werrorand added a valid minimal PE32+ fixture to the temporary test copy. The fixture declares exactly two data directories (NumberOfRvaAndSizes == 2), hasSizeOfOptionalHeader == 128(the 112-byte PE32+ fixed header plus the 16 bytes needed for export and import entries), and places the section table at the declared optional-header end. It includes valid imports and requestsmimalloc-redirect.dll. The PR rejects it withthe image has no imports.The guard currently requires
optionalSize >= ImportDirectory + 16, whereImportDirectoryis already 120, so it requires 136 bytes. The Import Directory entry at offset 120 is eight bytes; the correct lower bound for this entry is 128 bytes. Please add the 128-byte/two-directory regression and accept/reorder this valid image, while retaining the malformed-header tests. The existing focused suite passes with the current PR code, but does not cover this valid minimal optional header.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T13:28:11Z.
Review: DISMISSED
I rechecked the exact head
c039d1c476e21317d25e00cb11846226139be377. The out-of-file Name RVA case I reported earlier is now rejected and has a regression test; that issue is resolved. One valid-input regression remains: a PE32+ optional header of 128 bytes withNumberOfRvaAndSizes == 2contains the full Import Directory entry (directory table starts at offset 112; entry #1 occupies bytes 120–127). The current guard requiresoptionalSize >= ImportDirectory + 16(136 bytes), so it rejects this valid minimal header. I reproduced this with a synthetic image whose section table starts at the declared optional-header end and whose imports are otherwise valid. Please change the bound to cover the eight-byte entry and add the positive 128-byte/two-directory test; keep the malformed-header and no-mutation cases.This PR is based on
204c6747d0a1, while currentmainis0e5d5a54098c. I found no intervening changes to the two modified files, so the source review still applies, but CONTRIBUTING requires syncing to current main and rerunning conventions. Hosted eligibility/conventions/intake/labels pass; product and relinker jobs are skipped by path policy. The author-reported MinGW build/test evidence is useful but does not cover the missing valid-header case.