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

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

📋 Pull Request Information

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

Base: main ← Head: fix/isa-coverage-safety


📝 Commits (1)

  • 23fad63 tools: harden isa_coverage.py BOM, SyntaxError, encoding and zero-division paths

📊 Changes

2 files changed (+86 additions, -6 deletions)

View changed files

📝 tests/test_isa_coverage.py (+77 -0)
📝 tools/isa_coverage.py (+9 -6)

📄 Description

Claimed in the coordination issue as: ISA-COVERAGE-PARSER-BOM-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162112152)

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)

🔄 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/1799 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/isa-coverage-safety` --- ### 📝 Commits (1) - [`23fad63`](https://github.com/ubiquitarianism/leonida/commit/23fad6301f55693032e954c7446679fd62cf5f0b) tools: harden isa_coverage.py BOM, SyntaxError, encoding and zero-division paths ### 📊 Changes **2 files changed** (+86 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_isa_coverage.py` (+77 -0) 📝 `tools/isa_coverage.py` (+9 -6) </details> ### 📄 Description Claimed in the coordination issue as: ISA-COVERAGE-PARSER-BOM-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162112152) ### 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) --- <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#1811
No description provided.