d3d12_device_calls: validate --out upfront and publish reports atomically #2262

Open
github-bot wants to merge 1 commit from github-bot/gh-2262 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 11:35 UTC · original
kirigayakazima:fix/d3d12-device-calls-safety → main · +217 −13 · 2 files · 1 commits · open

Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (#1608)

What and why

tools/d3d12_device_calls.py previously read and scanned the PE image before validating --out or same_report_path(...), and wrote <image>.device_calls.json and .txt directly in place with open(..., "w"). An unusable --out or self-overwrite path wasted a full PE decode (or created an empty --out directory on unreadable images), and an interrupted or failing write could truncate or partially update the report pair.

  • Check --out (non-empty and directory ancestors), input/report path collisions (same_report_path), and directory-occupied report paths before reading or scanning the input image, deferring os.makedirs until scan output is ready to write.
  • Stage both .json and .txt outputs into UTF-8 LF temp files inside --out, copy/probe permissions via file_mode.published_mode(...), replace both via replace_retry.replace(...), and clean up any leftover staged files on error.
  • Add CLI tests covering upfront --out / collision / directory-target errors, unopened invalid images, and preservation of prior reports on staging failure.

Tested

  • python -I tests/test_d3d12_device_calls.py -v (19 tests passed)
  • Detached upstream/main baseline negative control: failed with the new CLI tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kirigayakazima** on GitHub · 2026-11-26 11:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2262) `kirigayakazima:fix/d3d12-device-calls-safety` → `main` · +217 −13 · 2 files · 1 commits · open Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/d3d12_device_calls.py` previously read and scanned the PE image before validating `--out` or `same_report_path(...)`, and wrote `<image>.device_calls.json` and `.txt` directly in place with `open(..., "w")`. An unusable `--out` or self-overwrite path wasted a full PE decode (or created an empty `--out` directory on unreadable images), and an interrupted or failing write could truncate or partially update the report pair. - Check `--out` (non-empty and directory ancestors), input/report path collisions (`same_report_path`), and directory-occupied report paths before reading or scanning the input image, deferring `os.makedirs` until scan output is ready to write. - Stage both `.json` and `.txt` outputs into UTF-8 LF temp files inside `--out`, copy/probe permissions via `file_mode.published_mode(...)`, replace both via `replace_retry.replace(...)`, and clean up any leftover staged files on error. - Add CLI tests covering upfront `--out` / collision / directory-target errors, unopened invalid images, and preservation of prior reports on staging failure. ### Tested - `python -I tests/test_d3d12_device_calls.py -v` (19 tests passed) - Detached `upstream/main` baseline negative control: failed with the new CLI tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:36:32 +00:00
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:23 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_d3d12_device_calls.py: 19 tests OK. The PR's test file against main's tool: 2 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2262#issuecomment-7191943517) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_d3d12_device_calls.py: 19 tests OK. The PR's test file against main's tool: 2 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:36 UTC · original · approved these changes

Approving 6dd813ddb.

--out and its existing ancestors are checked before the scan, and both reports are staged as temp files and replaced only once all are written.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_d3d12_device_calls.py: 19 passed (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2262#pullrequestreview-6083540144) · **approved these changes** Approving 6dd813ddb. `--out` and its existing ancestors are checked before the scan, and both reports are staged as temp files and replaced only once all are written. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_d3d12_device_calls.py`: 19 passed (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2262/head:github-bot/gh-2262'
git switch 'github-bot/gh-2262'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2262'
git switch 'github-bot/gh-2262'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2262'
git switch 'github-bot/gh-2262'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2262'
git switch 'main'
git merge --squash 'github-bot/gh-2262'
git switch 'main'
git merge --ff-only 'github-bot/gh-2262'
git switch 'main'
git merge 'github-bot/gh-2262'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.