[PR #943] d3d12_guid_sites, d3d12_iid_scan: report an unreadable header or import table (D3D12-TOOLS-ERROR-REPORTING) #981

Open
opened 2026-11-26 20:19:41 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/943
Author: @TuroYT
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/d3d12-tools-error-reporting


📝 Commits (1)

  • 255156c d3d12_guid_sites, d3d12_iid_scan: report an unreadable header or import table (D3D12-TOOLS-ERROR-REPORTING)

📊 Changes

4 files changed (+143 additions, -10 deletions)

View changed files

📝 tests/test_d3d12_guid_sites.py (+1 -1)
➕ tests/test_d3d12_guid_tools_errors.py (+106 -0)
📝 tools/d3d12_guid_sites.py (+11 -1)
📝 tools/d3d12_iid_scan.py (+25 -8)

📄 Description

Claimed in the coordination issue as: D3D12-TOOLS-ERROR-REPORTING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135584906)

What was wrong

  1. tools/d3d12_guid_sites.py:391 skipped a --header that 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 the
    same input with ERROR: d3d12.h not found; pass --header.
  2. Both tools, read_iids: the MIDL regex accepts any 36-character run of hex digits and dashes, and uuid.UUID
    then raises ValueError, which the OSError-only handler in main() did not catch. Reproduction with the header line
    MIDL_INTERFACE("000000000000000000000000000000000000"): traceback ending in
    ValueError: badly formed hexadecimal UUID string, in both tools.
  3. tools/d3d12_iid_scan.py:114: except (struct.error, ValueError): return None made a parse error look like "does not
    import 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: #50 and the
    warning, exit 0; the stub with an unterminated second import name prints neither. All three defects reproduced.

What changed

  • d3d12_guid_sites.py: an explicit --header that is not a file exits 2 with ERROR: d3d12.h not found: <path>.
    A malformed GUID exits 2 with ERROR: cannot read <header>: a MIDL_INTERFACE GUID is malformed (...). The same
    malformed-GUID error is in d3d12_iid_scan.py. The default SDK header lookup is unchanged.
  • d3d12_iid_scan.py: d3d12_xs_imports keeps its return value. A new read_d3d12_xs_imports also returns the reason the
    table 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). cstr now raises a named ValueError instead of a
    bare index failure.
  • tests/test_d3d12_guid_sites.py: test_cli passed a missing --header and expected exit 0. It now writes a header
    file that lists no interfaces.
  • tests/test_d3d12_guid_tools_errors.py (new): four tests on hand-made files in a temporary folder: missing header
    (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

  • Reproduction on origin/main before the change: the outputs listed above (guid_sites exit 0; both tools traceback on
    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.
  • The same file against the origin/main copies of the two tools (fixed copies restored afterwards): Ran 4 tests,
    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 15
    tests, 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.py on the four changed files: exit 0.
  • git diff --check: clean.

Not tested:

  • tests/test_d3d12_guid_sites_float4.py: it has no __main__ block, so python3 -I exits 0 without running a test.
    pytest is not installed here, so the file was not run under pytest.
  • A real d3d12.h from the Windows SDK, and the default header lookup on Windows.
  • Interaction with #487 (open, kotekompotek): it adds lines in main() just before the known block and does not touch
    the lines this PR changes. A rebase may be needed if #487 lands first.

Not changed, on purpose:

  • A name RVA outside every section (the literal RVA 0x1300) is still skipped silently. Without the name the parser
    cannot tell whether that import is d3d12_xs.dll, and reporting it would change the result for every image.
  • guid_sites still runs with no header GUIDs when the default SDK header is not found. Only an explicit --header is
    refused. Making the default an error is a behaviour change for hosts without an SDK.
  • A truncated import directory that ends between descriptors is still not warned about.
  • A file that starts with "MZ" but is shorter than a PE header now gets the import-table warning (it was silent).

AI-assisted (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/943 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/d3d12-tools-error-reporting` --- ### 📝 Commits (1) - [`255156c`](https://github.com/ubiquitarianism/leonida/commit/255156c2c88d55c94646d24622755c9b538def4f) d3d12_guid_sites, d3d12_iid_scan: report an unreadable header or import table (D3D12-TOOLS-ERROR-REPORTING) ### 📊 Changes **4 files changed** (+143 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_d3d12_guid_sites.py` (+1 -1) ➕ `tests/test_d3d12_guid_tools_errors.py` (+106 -0) 📝 `tools/d3d12_guid_sites.py` (+11 -1) 📝 `tools/d3d12_iid_scan.py` (+25 -8) </details> ### 📄 Description Claimed in the coordination issue as: D3D12-TOOLS-ERROR-REPORTING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135584906) ## What was wrong 1. tools/d3d12_guid_sites.py:391 skipped a `--header` that 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 the same input with `ERROR: d3d12.h not found; pass --header`. 2. Both tools, `read_iids`: the MIDL regex accepts any 36-character run of hex digits and dashes, and `uuid.UUID` then raises ValueError, which the OSError-only handler in main() did not catch. Reproduction with the header line `MIDL_INTERFACE("000000000000000000000000000000000000")`: traceback ending in `ValueError: badly formed hexadecimal UUID string`, in both tools. 3. tools/d3d12_iid_scan.py:114: `except (struct.error, ValueError): return None` made a parse error look like "does not import 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: #50` and the warning, exit 0; the stub with an unterminated second import name prints neither. All three defects reproduced. ## What changed - d3d12_guid_sites.py: an explicit `--header` that is not a file exits 2 with `ERROR: d3d12.h not found: <path>`. A malformed GUID exits 2 with `ERROR: cannot read <header>: a MIDL_INTERFACE GUID is malformed (...)`. The same malformed-GUID error is in d3d12_iid_scan.py. The default SDK header lookup is unchanged. - d3d12_iid_scan.py: `d3d12_xs_imports` keeps its return value. A new `read_d3d12_xs_imports` also returns the reason the table 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). `cstr` now raises a named ValueError instead of a bare `index` failure. - tests/test_d3d12_guid_sites.py: `test_cli` passed a missing `--header` and expected exit 0. It now writes a header file that lists no interfaces. - tests/test_d3d12_guid_tools_errors.py (new): four tests on hand-made files in a temporary folder: missing header (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 - Reproduction on origin/main before the change: the outputs listed above (guid_sites exit 0; both tools traceback on 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. - The same file against the origin/main copies of the two tools (fixed copies restored afterwards): Ran 4 tests, 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 15 tests, 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.py` on the four changed files: exit 0. - `git diff --check`: clean. Not tested: - tests/test_d3d12_guid_sites_float4.py: it has no `__main__` block, so `python3 -I` exits 0 without running a test. pytest is not installed here, so the file was not run under pytest. - A real d3d12.h from the Windows SDK, and the default header lookup on Windows. - Interaction with #487 (open, kotekompotek): it adds lines in main() just before the `known` block and does not touch the lines this PR changes. A rebase may be needed if #487 lands first. Not changed, on purpose: - A name RVA outside every section (the literal RVA 0x1300) is still skipped silently. Without the name the parser cannot tell whether that import is d3d12_xs.dll, and reporting it would change the result for every image. - guid_sites still runs with no header GUIDs when the default SDK header is not found. Only an explicit `--header` is refused. Making the default an error is a behaviour change for hosts without an SDK. - A truncated import directory that ends between descriptors is still not warned about. - A file that starts with "MZ" but is shorter than a PE header now gets the import-table warning (it was silent). AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#981
No description provided.