Repository navigation
fix(tools): accept PE libraries without export tables - #10618
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 5d6bc58bd028773973e25d8676a02461f6cc9e3c. pe_exports now returns an empty export set only when both export-directory fields are zero; partial, undersized, and unmapped directories still raise AuditError. The added tests cover both PE32 and PE32+, absence of requested NIDs, guest-module/library scans, and continued reporting of missing transitive host dependencies. On the exact head, python3 -m unittest tools.tests.test_import_audit passed (140 tests, 1 skipped), conventions passed, and git diff --check upstream/main...HEAD passed. Hosted eligibility/intake/conventions/labels pass; Linux relinker and ASan pass, while Windows/macOS relinker jobs remain in progress/queued. Those matrix jobs do not exercise the Python audit behavior; I did not run the Windows DLL integration test locally.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
roboterspinne
left a comment
There was a problem hiding this comment.
Reviewed head 5d6bc58 merged onto upstream/main dc9f1ef (2026-10-24); the merge is clean, also together with #10560 (same two files, no conflict), check_conventions.py passes and pr_overlap.py lists only the two base-conflicted PRs (#6171, #7454) the bot already names.
Environment: Windows 11 Home 10.0.26200, Python 3.13.9 (Anaconda), WinLibs GCC 15.2.0 for the DLL probe; Python only, no build needed.
Results
python -m unittest tools.tests.test_import_auditon the merged tree: 140 tests, 137 pass, 3 skipped, 7.7 s. Red/green: againstmain'simport_audit.pythe two reader tests error withPE file has no export tableand both CLI tests fail (the audit exits 2 with that message instead of 1 or 0); the malformed-directory control passes onmainas the body says; all four pass on the branch.- Real DLL:
gcc -shared -Wl,--exclude-all-symbolson a source without__declspec(dllexport)gives an export data directory ofrva 0, size 0;ctypes.WinDLLloads it;main'sread_exportsraisesPE file has no export table, the branch returns an empty set. A DLL with one export (rva 0x9000, size 75) reads['exported']on both. The exportless DLL still importsKERNEL32.dlland the UCRT API sets, so the dependency audit has something to check on it. - The new return sits after
pe_headershas validated the signature, the optional-header magic and size, the data-directory count and the section table, so a truncated or malformed header still raises before it;rva 0, size != 0andrva != 0, size < 40keep the old error.
Nits
test_import_audit.py:1559: the malformed-directory control uses a bareassertRaises(AuditError), so it would still pass if the fixture started failing earlier inpe_headers. Today(0, 40),(0x1000, 0)and(0x1000, 39)raisePE file has no export tableand(0xffffff, 40)raisesRVA 0xffffff is not inside any section, for both magics, onmainand on the branch;assertRaisesRegex(import_audit.AuditError, "no export table|not inside any section")would pin the intended failure and passes on both.test_import_audit.py:1542-1549: the PE32 subtest of the positive test does not pin the PE32 directory offset:build_pe([])leaves a valid empty export entry at0x58 + 112, so the subtest would also pass withPE_DIRECTORY_OFFSET[0x10b]wrongly set to 112. Only the malformed control'smagic=0x10bcases catch that; writing a malformed entry such as(0x1000, 39)at0x58 + 112in the positive fixture would make the PE32 half self-sufficient. Optional.
Notes, nothing to change here: the PE/COFF data-directory text never defines a "no table" encoding; the Windows loader treats VirtualAddress 0 as absent whatever Size says (a patched (0, 40) DLL loads and GetProcAddress fails with ERROR_PROC_NOT_FOUND), while the branch keeps rejecting it and pe_imports in the same file treats rva 0 as absent regardless of size; no linker I could check emits (0, n), so accepting only (0, 0) is a defensible choice, just stricter than the loader. (0x1000, 0) is rightly still an error, the loader follows that RVA into garbage. The guest-module half of test_audit_accepts_pe_libraries_and_modules_without_export_directories shows that read_modules no longer raises, not that module dependencies are audited: read_modules records ([], []) for every PE module's imports, as on main. The body's 33.43 s for the audit ctest is the author's host; here the suite takes 7.7 s and CI 0.8 to 8.4 s.
Not checked: an MSVC- or lld-linked exportless DLL, macOS and Linux runs, the body's pr_overlap adapter and its manual three-way merges with #6171 and #7454.
I found no blocking issue: (0, 0) is what GNU ld writes for an exportless DLL and what Windows loads, the return sits after every header check, an exportless library stays present for the dependency audit and cannot satisfy a NID, elf_exports already behaves the same way for an ELF without SHT_DYNSYM, and the counter-check holds for all four tests. For disclosure: I have open PRs (#10667 on tools/tests/test_suggest_patches.py, and relinker PRs #10658, #10646, #10607, #10596, #10564, #10403, #10402, #10401, #10391, #10390); none touches these files.
Written with AI assistance (Claude Code). I ran the tests and the DLL probe above on my Windows 11 machine.
| struct.pack_into("<I", image, 0x58 + directory - 4, 16) | ||
| struct.pack_into("<II", image, 0x58 + directory, rva, size) | ||
| with self.subTest(magic=magic, rva=rva, size=size): | ||
| with self.assertRaises(import_audit.AuditError): |
There was a problem hiding this comment.
Nit: a bare assertRaises also passes if the fixture starts failing earlier in pe_headers. Today the three partial pairs raise PE file has no export table and (0xffffff, 40) raises RVA 0xffffff is not inside any section, on both magics, on main and here; assertRaisesRegex(import_audit.AuditError, "no export table|not inside any section") pins the intended failure and passes on both.
| struct.pack_into("<I", image, 0x58 + directory - 4, 16) | ||
| struct.pack_into("<II", image, 0x58 + directory, 0, 0) | ||
| with self.subTest(magic=magic): | ||
| self.assertEqual(import_audit.read_exports(Path("empty.prx"), image), set()) |
There was a problem hiding this comment.
Nit, optional: the magic=0x10b subtest would also pass with PE_DIRECTORY_OFFSET[0x10b] wrongly set to 112, because build_pe([]) leaves a valid empty export entry at 0x58 + 112; only the malformed control pins the PE32 offset. A malformed entry such as (0x1000, 39) at 0x58 + 112 in this fixture would make the PE32 half catch that on its own.
THEMANnt
left a comment
There was a problem hiding this comment.
Reviewed 5d6bc58bd028 against pinned base 6cd36e651724. No actionable findings in this focused review.
Source review
pe_exports now returns an empty set only when both export-directory fields are zero, after the existing header checks. Partial entries, undersized tables, and unmapped addresses still fail. Empty exports preserve library presence, while dependency auditing runs separately. The tests exercise both PE directory layouts, converted guest modules, absent requested NIDs, and missing host dependencies through the real audit entry point with isolated fixtures.
Validation
Controller-recorded tools/tests/test_import_audit.py execution on Windows, Python 3.11.9:
- Baseline: 133 passed, 3 skipped; 136 total.
- Pristine PR and candidate: each 137 passed, 3 skipped; 140 total. No local amendments were applied.
- Old-code control: two CLI assertion failures showed the previous exit-2 rejection; two reader subtest errors raised the same
AuditError. The control stops before the later missing-NID assertions, which pass on the candidate. - Recorded whitespace and conventions checks passed.
GitHub reports success for relinker-asan, the listed Windows/Ubuntu/macOS relinker jobs, eligibility, conventions, labels, and intake. write-watch, linux, windows, and register-context were skipped.
Scope
Validation covers the Python tool; full application behavior was not tested. The author's compiled-DLL/LoadLibrary and Python 3.12.14/CTest checks were not independently reproduced.
What
import_audit.pyaborts withPE file has no export tablewhen a valid library has a zero export-directory address and size. Such a library can still import host dependencies and needs to participate in the audit. An independently compiled DLL with no exports loads successfully through Windows but fails the current reader.After the existing PE header checks, return an empty export set when both directory fields are zero. Preserve errors for partial or malformed directories and keep dependency auditing active. Tests cover both PE32/PE32+ directory layouts, built-library and guest-module scans, absent requested NIDs and missing transitive host dependencies.
Tested
Windows x86-64, Python 3.12.14, CMake 4.3.1, WinLibs GCC 15.2.0; baseline main
8ec6397b3762fa23f90a6973d223b12553e420a5:gcc -shared -Wl,--exclude-all-symbols; its export-directory pair is(0, 0). WindowsLoadLibrarythroughctypes.WinDLLsucceeds. Main raisesAuditError; this change returns an empty set while retaining all six imported host-library names. A separate root-level harness independently confirms the same result.ctest --test-dir build-relinker -R '^(import_audit|test_script_registration)$' --output-on-failure -V: 2/2 passed. The audit suite ran 140 tests: 137 passed and 3 platform/privilege tests skipped. Audit CTest took 33.43 seconds on this host; all 175 Python test scripts are registered. Existing hardlink-protection tests ran successfully outside sandbox restrictions.git diff --check origin/main...HEADpass. The older queued worktree and its uncommitted source/tests remain untouched.tools/pr_overlap.py --branch fix/import-audit-empty-pe-exportschecked 1,249 open PRs. It found no confirmed overlap. Two base-conflicted comparisons were manually checked at exact heads: fix(tools): recognize guest module identities in import audit #6171 (35bf15c510cb50ee8152d911c686e5eccdb95c15) and fix(tools): resolve $ORIGIN-prefixed converted module dependencies in import_audit #7454 (11840ad87c4065873cb2923b2367232d33bbe5ee). Paired three-way merges preserve every existing conflict block and add none; their behavior changes concern module identities and$ORIGINdependency matching. Neither changes PE export parsing. No dependency. The unmodified repository checker used a local adapter for public GitHub pagination becauseghis unavailable.No title, console hardware, GPU or full system-library build was tested.
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)