d3d12_xs_surface: guard GUID negative bounds, SCARAB BOM/CRLF, and bad paths #2263

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

@⁠kirigayakazima on GitHub · 2026-11-26 11:39 UTC · original
kirigayakazima:fix/d3d12-xs-surface-safety → main · +148 −45 · 2 files · 1 commits · open

Claimed in the coordination issue as: D3D12-XS-SURFACE-SCARAB-CRLF-BOM-AND-GUID-BOUNDS (#1608)

What and why

tools/d3d12_xs_surface.py had three validation and SCARAB parsing gaps:

  • check_guid_values() checked upper bounds on GUID fields (> 0xFFFFFFFF, > 0xFFFF, > 0xFF) without rejecting negative components (< 0).
  • parse_scarab_iid_table(), parse_scarab_iid_console(), and parse_scarab_catalogue() opened files with "utf-8" instead of "utf-8-sig", and parse_scarab_catalogue() stripped only "\n" instead of "\r\n".
  • check_scarab() checked os.path.exists(...) rather than directory/regular-file validity and let OSError/UnicodeDecodeError/ValueError crash unhandled, while main() used if args.scarab: so --scarab "" silently skipped checking and returned 0.

This updates the bounds checks, opens SCARAB inputs with utf-8-sig and rstrip("\r\n"), reports invalid/unreadable SCARAB paths as errors entries, checks args.scarab is not None, and adds unit/CLI tests for these cases.

Tested

  • python -I tests/test_d3d12_xs_surface.py
  • python -I tools/d3d12_xs_surface.py --check
  • Detached upstream/main baseline negative control: failed with the new 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:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2263) `kirigayakazima:fix/d3d12-xs-surface-safety` → `main` · +148 −45 · 2 files · 1 commits · open Claimed in the coordination issue as: D3D12-XS-SURFACE-SCARAB-CRLF-BOM-AND-GUID-BOUNDS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/d3d12_xs_surface.py` had three validation and SCARAB parsing gaps: - `check_guid_values()` checked upper bounds on GUID fields (`> 0xFFFFFFFF`, `> 0xFFFF`, `> 0xFF`) without rejecting negative components (`< 0`). - `parse_scarab_iid_table()`, `parse_scarab_iid_console()`, and `parse_scarab_catalogue()` opened files with `"utf-8"` instead of `"utf-8-sig"`, and `parse_scarab_catalogue()` stripped only `"\n"` instead of `"\r\n"`. - `check_scarab()` checked `os.path.exists(...)` rather than directory/regular-file validity and let `OSError`/`UnicodeDecodeError`/`ValueError` crash unhandled, while `main()` used `if args.scarab:` so `--scarab ""` silently skipped checking and returned 0. This updates the bounds checks, opens SCARAB inputs with `utf-8-sig` and `rstrip("\r\n")`, reports invalid/unreadable SCARAB paths as `errors` entries, checks `args.scarab is not None`, and adds unit/CLI tests for these cases. ### Tested - `python -I tests/test_d3d12_xs_surface.py` - `python -I tools/d3d12_xs_surface.py --check` - Detached `upstream/main` baseline negative control: failed with the new 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:42:18 +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_xs_surface.py ends "ok" (the Windows SDK header check and the SCARAB_REF check skip here, as expected on Linux). The PR's test file against main's tool fails in test_check_guid_values_rejects_negative_components (AssertionError: []), so the new test fails on main and passes 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/2263#issuecomment-7191942815) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_d3d12_xs_surface.py ends "ok" (the Windows SDK header check and the SCARAB_REF check skip here, as expected on Linux). The PR's test file against main's tool fails in test_check_guid_values_rejects_negative_components (AssertionError: []), so the new test fails on main and passes 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 15d9ec971.

The GUID check now catches negative fields as well as oversized ones, the SCARAB tables are read BOM- and CRLF-tolerant, and a missing or unreadable checkout or table is reported as an error instead of raising.

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_xs_surface.py: 11 passed, 2 skipped (main: 8). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2263#pullrequestreview-6083541281) · **approved these changes** Approving 15d9ec971. The GUID check now catches negative fields as well as oversized ones, the SCARAB tables are read BOM- and CRLF-tolerant, and a missing or unreadable checkout or table is reported as an error instead of raising. 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_xs_surface.py`: 11 passed, 2 skipped (main: 8). 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/2263/head:github-bot/gh-2263'
git switch 'github-bot/gh-2263'

Merge

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