inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base #2273
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2273"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:59:26Z.
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.pypreviously:"utf-8"instead of"utf-8-sig", causing line 1 to missLINEmatching when a file started with a UTF-8 BOM.dumpbinviasubprocess.Popenwithoutencoding="utf-8"ortry/finallycleanup, risking locale-dependent decoding and leaking/leavingdumpbinrunning if iteration stopped early.main()with noargvparameter, accepted negative--basevalues (like-0x1000), and letOSErrorfrom reading listings crash unhandled instead of exiting 2.This uses
"utf-8-sig"for listings, addsencoding="utf-8"andtry/finallypipe/process cleanup inread_lines(), adds_parse_baserejecting negative hex bases, acceptsargv=Noneinmain(), handlesOSErrorcleanly, and adds unit/CLI tests intests/test_inline_scan.py.Tested
python -I tests/test_inline_scan.py -v(17 passed)upstream/mainbaseline negative control: failed with the new tests before the fixpython -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, andgit diff --cached --checkGPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:21Z.
Checked on main
a73a57e1(Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly, compileall clean, but one of the new tests fails with this PR:python -I tests/test_inline_scan.py: 17 run, FAILED (failures=1), in test_negative_base_and_oserror_return_2:
AssertionError: 'non-negative' not found in 'usage: test_inline_scan.py [-h] [--base BASE] [--sites] source
test_inline_scan.py: error: argument --base: expected one argument'
argparse only treats decimal negatives like -1 as values, so "--base", "-0x1000" is parsed as a missing argument followed by an unknown option, and the new non-negative check in _parse_base is never reached. The same happens on the command line: python -I tools/inline_scan.py x.txt --base -0x1000 prints "argument --base: expected one argument". With the test changed to inline_scan.main([path, "--base=-0x1000"]), all 17 pass, and the new tests fail on main (1 failure, 2 errors) as they should. If negative bases should be caught as written in the usage line, the check may need the --base=... form documented or a different parser setup.
AI-assisted: yes (Claude Code)
Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T12:52:26Z.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
tests/test_inline_scan.py: 1 failed, 16 passed.test_negative_base_and_oserror_return_2.inline_scan.main([path, "--base", "-0x1000"])exits 2, but from argparse itself (argument --base: expected one argument), so"non-negative"is not in stderr.-1as negative values.-0x1000looks like an option, so--basegets no value. This is not Windows-specific.--base=-0x1000in the test (or a decimal value such as-4096) would reach the tool's own check.(AI-assisted test run; output checked by hand.)
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:38:41Z.
Review: CHANGES_REQUESTED
Requesting one change in the new test; the code change itself looks right.
test_negative_base_and_oserror_return_2callsinline_scan.main([path, "--base", "-0x1000"])and fails on its own head (757ffc364) with Python 3.13: argparse only treats decimal negatives such as-5as values, so-0x1000is taken for an unknown option and the run stops with "argument --base: expected one argument" before_parse_baseis called. The exit code is still 2, but the "non-negative" assertion fails:Writing it as
"--base=-0x1000"passes the value on every Python and actually reaches the new check. The other tests pass (16 of 17 intests/test_inline_scan.py, onmaind1dff7949plus this PR). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T11:55:08Z.
Thanks @tiguan26, @real-rusher, and @DeadlyChirp — fixed in the test by passing
--base=-0x1000(and also testing decimal--base -16) soargparsedelivers the negative value to_parse_base.python -I tests/test_inline_scan.py -vand the 5 repository checks pass.Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T18:42:28Z.
Review: APPROVED
Approving now.
2de87e5eafixes what I asked for: with--base=-0x1000(and--base -16, which argparse accepts as a negative number) the value reaches_parse_base, so the test now checks the real "image base must be non-negative" error instead of argparse's unknown-option one.Checked on
2de87e5eamerged onto current main (43a9d562d), no conflicts:tests/test_inline_scan.py17 passed (2 subtests). From the command line, bothtools/inline_scan.py <file> --base=-0x1000and--base -16printargument --base: image base must be non-negativeand exit 2.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:08:00Z.
Red/green:
pytest tests/test_inline_scan.pyfails on main (5 failed, 14 passed) and passes on head2de87e5ea1merged with main (17 passed, 2 subtests passed).Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)