[PR #2262] d3d12_device_calls: validate --out upfront and publish reports atomically #2266

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2262
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/d3d12-device-calls-safety


📝 Commits (1)

  • 6dd813d d3d12_device_calls: validate --out upfront and publish reports atomically

📊 Changes

2 files changed (+217 additions, -13 deletions)

View changed files

📝 tests/test_d3d12_device_calls.py (+147 -0)
📝 tools/d3d12_device_calls.py (+70 -13)

📄 Description

Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7190884297)

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.

🔄 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/2262 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/d3d12-device-calls-safety` --- ### 📝 Commits (1) - [`6dd813d`](https://github.com/ubiquitarianism/leonida/commit/6dd813ddb1eedbac60c30af41403ae99f83f45f4) d3d12_device_calls: validate --out upfront and publish reports atomically ### 📊 Changes **2 files changed** (+217 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_d3d12_device_calls.py` (+147 -0) 📝 `tools/d3d12_device_calls.py` (+70 -13) </details> ### 📄 Description Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7190884297) ### 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. --- <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#2266
No description provided.