spirv_asm: validate --out upfront, accept UTF-8 BOM, and write atomically #2264

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

@⁠kirigayakazima on GitHub · 2026-11-26 11:44 UTC · original
kirigayakazima:fix/spirv-asm-cli-safety → main · +125 −3 · 2 files · 1 commits · open

Claimed in the coordination issue as: SPIRV-ASM-CLI-BOM-DIR-GUARD-AND-ATOMIC-WRITE (#1608)

What and why

tools/spirv_asm.py previously:

  • Read the .spvasm input before validating --out, causing full assembly before rejecting empty paths, directories, or missing parent directories.
  • Opened .spvasm with "utf-8" instead of "utf-8-sig", rejecting UTF-8 BOM inputs with unknown opcode '\ufeff...'.
  • Wrote binary .spv output directly in place with open(args.out, "wb"), risking truncated or corrupted existing outputs if a write failed partway.

This adds _check_out_path upfront in main(), reads source files with utf-8-sig (keeping newline=""), publishes assembled SPIR-V atomically with tempfile + file_mode.published_mode + replace_retry.replace, and adds unit/CLI tests covering all three behaviors.

Tested

  • python -I tests/test_spirv_asm.py -v: 41 tests run (40 passed; 1 skipped: spirv-as not installed)
  • Detached upstream/main baseline negative control: failed on the new CLI tests before the fix
  • python -I tests/test_ci_registration.py (16 passed), python -I tests/test_text_write_line_endings.py (3 passed), 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:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2264) `kirigayakazima:fix/spirv-asm-cli-safety` → `main` · +125 −3 · 2 files · 1 commits · open Claimed in the coordination issue as: SPIRV-ASM-CLI-BOM-DIR-GUARD-AND-ATOMIC-WRITE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/spirv_asm.py` previously: - Read the `.spvasm` input before validating `--out`, causing full assembly before rejecting empty paths, directories, or missing parent directories. - Opened `.spvasm` with `"utf-8"` instead of `"utf-8-sig"`, rejecting UTF-8 BOM inputs with `unknown opcode '\ufeff...'`. - Wrote binary `.spv` output directly in place with `open(args.out, "wb")`, risking truncated or corrupted existing outputs if a write failed partway. This adds `_check_out_path` upfront in `main()`, reads source files with `utf-8-sig` (keeping `newline=""`), publishes assembled SPIR-V atomically with `tempfile` + `file_mode.published_mode` + `replace_retry.replace`, and adds unit/CLI tests covering all three behaviors. ### Tested - `python -I tests/test_spirv_asm.py -v`: 41 tests run (40 passed; 1 skipped: `spirv-as not installed`) - Detached `upstream/main` baseline negative control: failed on the new CLI tests before the fix - `python -I tests/test_ci_registration.py` (16 passed), `python -I tests/test_text_write_line_endings.py` (3 passed), `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:47:48 +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_spirv_asm.py: 41 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/2264#issuecomment-7191941971) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_spirv_asm.py: 41 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:37 UTC · original · approved these changes

Approving 9569d1806.

--out is checked (not empty, not a directory, parent exists) before the source is read, the source is read BOM-tolerant, and the module is published through a temp file and replace_retry.

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_spirv_asm.py: 41 passed (main: 38). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2264#pullrequestreview-6083542156) · **approved these changes** Approving 9569d1806. `--out` is checked (not empty, not a directory, parent exists) before the source is read, the source is read BOM-tolerant, and the module is published through a temp file and `replace_retry`. 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_spirv_asm.py`: 41 passed (main: 38). 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/2264/head:github-bot/gh-2264'
git switch 'github-bot/gh-2264'

Merge

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