inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base #2273
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2273
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/inline-scan-safety"
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?
Pull request successfully merged and closed
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.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)
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.)
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.Approving now. 2de87e5ea fixes 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 2de87e5ea merged 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.Red/green:
pytest tests/test_inline_scan.pyfails on main (5 failed, 14 passed) and passes on head 2de87e5ea1e7 merged with main (17 passed, 2 subtests passed).Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)