d3d12_guid_sites, d3d12_iid_scan: report an unreadable header or import table (D3D12-TOOLS-ERROR-REPORTING) #943
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/943"
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 TuroYT on 2026-11-24T15:25:45Z.
Claimed in the coordination issue as: D3D12-TOOLS-ERROR-REPORTING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135584906)
What was wrong
--headerthat does not exist (if header and os.path.isfile(header)).Reproduction on main with a 2-byte image and a missing header:
0 known GUIDs from .../no_such_d3d12.h,skipped (unpack_from requires a buffer of at least 64 bytes ...), exit 0. tools/d3d12_iid_scan.py exits 2 on thesame input with
ERROR: d3d12.h not found; pass --header.read_iids: the MIDL regex accepts any 36-character run of hex digits and dashes, anduuid.UUIDthen raises ValueError, which the OSError-only handler in main() did not catch. Reproduction with the header line
MIDL_INTERFACE("000000000000000000000000000000000000"): traceback ending inValueError: badly formed hexadecimal UUID string, in both tools.except (struct.error, ValueError): return Nonemade a parse error look like "does notimport d3d12_xs.dll", so the "imports may be IID data" warning was lost. Reproduction with two hand-built PE32+
stubs (a few hundred bytes, written by the test): the good stub prints
imports from d3d12_xs.dll: #50and thewarning, exit 0; the stub with an unterminated second import name prints neither. All three defects reproduced.
What changed
--headerthat is not a file exits 2 withERROR: d3d12.h not found: <path>.A malformed GUID exits 2 with
ERROR: cannot read <header>: a MIDL_INTERFACE GUID is malformed (...). The samemalformed-GUID error is in d3d12_iid_scan.py. The default SDK header lookup is unchanged.
d3d12_xs_importskeeps its return value. A newread_d3d12_xs_importsalso returns the reason thetable could not be read to its end. Names read before the error stay in the list, a one-line WARNING goes to stderr
naming the image, and the exit code stays 0 as on main. The JSON report gets a new key,
d3d12_xs_import_error(null when the table reads to its end).cstrnow raises a named ValueError instead of abare
indexfailure.test_clipassed a missing--headerand expected exit 0. It now writes a headerfile that lists no interfaces.
(both tools), malformed GUID (both tools), unreadable import table (warning, names kept, no traceback), and a good
header with a good stub (unchanged output).
The stub layout for defect 3 differs from the one in the report. A descriptor at file offset 0x214 overlaps the name
string at 0x220, so the name is at 0x230 (RVA 0x1030) here, and the unterminated name is at RVA 0x10F8 (file 0x2F8),
inside the section. With RVA 0x1300 the name is outside the section, and the parser skips that descriptor without an
error (see below).
Tested
the malformed GUID; iid_scan on the bad stub prints no imports line and no warning).
python3 -I tests/test_d3d12_guid_tools_errors.py: Ran 4 tests, OK.4 failures, one per new defect test (missing header in guid_sites, malformed GUID in both tools, the bad-stub warning).
python3 -I tests/test_d3d12_guid_sites.py: Ran 10 tests, OK.python3 -I tests/test_d3d12_iid_scan.py: Ran 15tests, OK.
python3 -I tests/test_missing_input_exit_codes.py: Ran 2 tests, OK.python3 -m compileall -q tools tests: exit 0.python3 -I tests/test_text_write_line_endings.py: OK.python3 -I scripts/check_no_game_data.pyon the four changed files: exit 0.git diff --check: clean.Not tested:
__main__block, sopython3 -Iexits 0 without running a test.pytest is not installed here, so the file was not run under pytest.
knownblock and does not touchthe lines this PR changes. A rebase may be needed if #487 lands first.
Not changed, on purpose:
cannot tell whether that import is d3d12_xs.dll, and reporting it would change the result for every image.
--headerisrefused. Making the default an error is a behaviour change for hosts without an SDK.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:30:20Z.
Review: CHANGES_REQUESTED
The new warning covers an unterminated import-name string, but the parser still silently treats other truncated tables as complete. The existing synthetic regression
test_truncated_file_rva_past_eof_keeps_prior_importsintests/test_d3d12_iid_scan.pyplaces the second descriptor’s thunk RVA exactly at EOF after a valid#80import.offset()returnsNone, the thunk loop exits normally, andread_d3d12_xs_imports()returns(["#80"], None). Consequentlyscan()and the CLI emit nod3d12_xs_import_errorwarning even though the table was not read to its end. The descriptor loop similarly exits silently if fewer than 20 bytes remain before a null descriptor.Could you distinguish a valid terminator / absent table from an unmappable RVA or truncated descriptor/thunk sequence, and report those as incomplete while retaining already-read names? Please extend the synthetic tests to assert the CLI warning and JSON error for the existing truncated-thunk fixture (and, ideally, a truncated descriptor table). The current test suite passes, but it does not assert the new warning on these already-covered truncation cases.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:28:40Z.
Red/green:
python -I tests/test_d3d12_guid_sites.py ; python -I tests/test_d3d12_guid_tools_errors.pyfails on main09c153948and passes on head255156c2c8merged with main (retest1).Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)