[PR #2273] inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base #2277

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

📋 Pull Request Information

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

Base: main ← Head: fix/inline-scan-safety


📝 Commits (1)

  • 757ffc3 inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base

📊 Changes

2 files changed (+111 additions, -8 deletions)

View changed files

📝 tests/test_inline_scan.py (+79 -0)
📝 tools/inline_scan.py (+32 -8)

📄 Description

Claimed in the coordination issue as: INLINE-SCAN-BOM-DUMPBIN-CLEANUP-AND-CLI-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191397017)

What and why

tools/inline_scan.py previously:

  • Opened text listings with "utf-8" instead of "utf-8-sig", causing line 1 to miss LINE matching when a file started with a UTF-8 BOM.
  • Spawned dumpbin via subprocess.Popen without encoding="utf-8" or try/finally cleanup, risking locale-dependent decoding and leaking/leaving dumpbin running if iteration stopped early.
  • Defined main() with no argv parameter, accepted negative --base values (like -0x1000), and let OSError from reading listings crash unhandled instead of exiting 2.

This uses "utf-8-sig" for listings, adds encoding="utf-8" and try/finally pipe/process cleanup in read_lines(), adds _parse_base rejecting negative hex bases, accepts argv=None in main(), handles OSError cleanly, and adds unit/CLI tests in tests/test_inline_scan.py.

Tested

  • python -I tests/test_inline_scan.py -v (17 passed)
  • 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.

🔄 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/2273 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/inline-scan-safety` --- ### 📝 Commits (1) - [`757ffc3`](https://github.com/ubiquitarianism/leonida/commit/757ffc364b1635fd8ed45baee2ba457cc45373b9) inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base ### 📊 Changes **2 files changed** (+111 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_inline_scan.py` (+79 -0) 📝 `tools/inline_scan.py` (+32 -8) </details> ### 📄 Description Claimed in the coordination issue as: INLINE-SCAN-BOM-DUMPBIN-CLEANUP-AND-CLI-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191397017) ### What and why `tools/inline_scan.py` previously: - Opened text listings with `"utf-8"` instead of `"utf-8-sig"`, causing line 1 to miss `LINE` matching when a file started with a UTF-8 BOM. - Spawned `dumpbin` via `subprocess.Popen` without `encoding="utf-8"` or `try/finally` cleanup, risking locale-dependent decoding and leaking/leaving `dumpbin` running if iteration stopped early. - Defined `main()` with no `argv` parameter, accepted negative `--base` values (like `-0x1000`), and let `OSError` from reading listings crash unhandled instead of exiting 2. This uses `"utf-8-sig"` for listings, adds `encoding="utf-8"` and `try/finally` pipe/process cleanup in `read_lines()`, adds `_parse_base` rejecting negative hex bases, accepts `argv=None` in `main()`, handles `OSError` cleanly, and adds unit/CLI tests in `tests/test_inline_scan.py`. ### Tested - `python -I tests/test_inline_scan.py -v` (17 passed) - 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. --- <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#2277
No description provided.