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

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/2264
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/spirv-asm-cli-safety


📝 Commits (1)

  • 9569d18 spirv_asm: validate --out upfront, accept UTF-8 BOM, and write atomically

📊 Changes

2 files changed (+125 additions, -3 deletions)

View changed files

📝 tests/test_spirv_asm.py (+82 -0)
📝 tools/spirv_asm.py (+43 -3)

📄 Description

Claimed in the coordination issue as: SPIRV-ASM-CLI-BOM-DIR-GUARD-AND-ATOMIC-WRITE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191092674)

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.

🔄 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/2264 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/spirv-asm-cli-safety` --- ### 📝 Commits (1) - [`9569d18`](https://github.com/ubiquitarianism/leonida/commit/9569d180657b0e50a25eaec9ecca17969d086af0) spirv_asm: validate --out upfront, accept UTF-8 BOM, and write atomically ### 📊 Changes **2 files changed** (+125 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_spirv_asm.py` (+82 -0) 📝 `tools/spirv_asm.py` (+43 -3) </details> ### 📄 Description Claimed in the coordination issue as: SPIRV-ASM-CLI-BOM-DIR-GUARD-AND-ATOMIC-WRITE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191092674) ### 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. --- <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#2267
No description provided.