tools: harden isa_coverage.py BOM, SyntaxError, encoding and zero-division paths #1799

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

@⁠kirigayakazima on GitHub · 2026-11-25 12:16 UTC · original
kirigayakazima:fix/isa-coverage-safety → main · +86 −6 · 2 files · 1 commits · open

Claimed in the coordination issue as: ISA-COVERAGE-PARSER-BOM-AND-ENCODING-SAFETY (#1608)

What and why

  • Read --translator with encoding="utf-8-sig" in scan_translator() and accepted_names() so files carrying a UTF-8 BOM do not fail ast.parse().
  • Catch (SyntaxError, ValueError) in main() when parsing --translator and report it via ap.error(...) (exit 2) instead of an unhandled traceback.
  • Guard markdown() against empty ISA instruction tables (0 instructions -> 0.0% instead of ZeroDivisionError).
  • Normalize empty or whitespace-only <EncodingName> elements in read_isa() to "OTHER:?".
  • Pass encoding="utf-8", errors="replace" to subprocess.run() in probe_llvm_mc() so python -I does not fail decoding tool diagnostics on ANSI code pages.
  • Add synthetic regression tests in tests/test_isa_coverage.py.

Tested

  • python -I tests/test_isa_coverage.py -v -> Ran 27 tests in 20.636s, OK (skipped=4) (real AMD ISA XML tests skipped without XML path; verified in a detached upstream/main worktree that all new tests fail before the fix: FAILED (failures=2, errors=4, skipped=4)).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.530s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.503s, OK.
  • python -I scripts/check_no_game_data.py tools/isa_coverage.py tests/test_isa_coverage.py -> exit 0.
  • python -I -m compileall -q tools/isa_coverage.py tests/test_isa_coverage.py and git diff --check -> clean.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

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. (n/a)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1799) `kirigayakazima:fix/isa-coverage-safety` → `main` · +86 −6 · 2 files · 1 commits · open Claimed in the coordination issue as: ISA-COVERAGE-PARSER-BOM-AND-ENCODING-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Read `--translator` with `encoding="utf-8-sig"` in `scan_translator()` and `accepted_names()` so files carrying a UTF-8 BOM do not fail `ast.parse()`. - Catch `(SyntaxError, ValueError)` in `main()` when parsing `--translator` and report it via `ap.error(...)` (exit `2`) instead of an unhandled traceback. - Guard `markdown()` against empty ISA instruction tables (`0` instructions -> `0.0%` instead of `ZeroDivisionError`). - Normalize empty or whitespace-only `<EncodingName>` elements in `read_isa()` to `"OTHER:?"`. - Pass `encoding="utf-8", errors="replace"` to `subprocess.run()` in `probe_llvm_mc()` so `python -I` does not fail decoding tool diagnostics on ANSI code pages. - Add synthetic regression tests in `tests/test_isa_coverage.py`. ### Tested - `python -I tests/test_isa_coverage.py -v` -> `Ran 27 tests in 20.636s`, `OK (skipped=4)` (real AMD ISA XML tests skipped without XML path; verified in a detached `upstream/main` worktree that all new tests fail before the fix: `FAILED (failures=2, errors=4, skipped=4)`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.530s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.503s`, `OK`. - `python -I scripts/check_no_game_data.py tools/isa_coverage.py tests/test_isa_coverage.py` -> exit `0`. - `python -I -m compileall -q tools/isa_coverage.py tests/test_isa_coverage.py` and `git diff --check` -> clean. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) 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. (n/a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:05:59 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-25 13:01 UTC · original · reviewed

Independent Windows 11 26H2 (26300.9711) check at 23fad6301 against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_isa_coverage.py (23 passed, 4 skipped without LEONIDA_RDNA2_ISA_XML, 20.786s), test_ci_registration.py (16/16, 6.163s), and test_text_write_line_endings.py (3/3, 15.982s), with check_no_game_data.py and compileall clean. Confirmed UTF-8 BOM scanning, SyntaxError/NUL-byte usage errors (preserving UnicodeDecodeError precedence), encoding="utf-8", errors="replace" in probe_llvm_mc() for Windows python -I, empty/whitespace normalization to OTHER:?, and zero-instruction markdown() handling. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-25 13:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1799#pullrequestreview-6058086841) · **reviewed** Independent Windows 11 26H2 (26300.9711) check at 23fad6301 against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_isa_coverage.py (23 passed, 4 skipped without LEONIDA_RDNA2_ISA_XML, 20.786s), test_ci_registration.py (16/16, 6.163s), and test_text_write_line_endings.py (3/3, 15.982s), with check_no_game_data.py and compileall clean. Confirmed UTF-8 BOM scanning, SyntaxError/NUL-byte usage errors (preserving UnicodeDecodeError precedence), encoding="utf-8", errors="replace" in probe_llvm_mc() for Windows python -I, empty/whitespace <EncodingName> normalization to OTHER:?, and zero-instruction markdown() handling. LGTM.
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 17:20 UTC · original · approved these changes

Verified on the PR branch: python3 -m unittest tests.test_isa_coverage -v -> 27 tests OK (4 skips), including the new BOM, SyntaxError/NUL, and zero-instruction markdown cases. The hardenings are appropriate for a tool that parses arbitrary translator source text. Python-only, no game data.

**@⁠MSedgeMC** on GitHub · 2026-11-25 17:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1799#pullrequestreview-6061962165) · **approved these changes** Verified on the PR branch: python3 -m unittest tests.test_isa_coverage -v -> 27 tests OK (4 skips), including the new BOM, SyntaxError/NUL, and zero-instruction markdown cases. The hardenings are appropriate for a tool that parses arbitrary translator source text. Python-only, no game data.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 17:27 UTC · original

Thanks. The new guards cover inputs that don't occur: --translator is the repository's own rdna2spirv.py, which has no BOM, and the AMD ISA XML always has its tables and encoding names.

Can you name a real input that hits them? Otherwise we'd rather not take the extra code.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 17:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1799#issuecomment-7169533773) Thanks. The new guards cover inputs that don't occur: `--translator` is the repository's own `rdna2spirv.py`, which has no BOM, and the AMD ISA XML always has its tables and encoding names. Can you name a real input that hits them? Otherwise we'd rather not take the extra code. 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/1799/head:github-bot/gh-1799'
git switch 'github-bot/gh-1799'

Merge

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