bcpack_tool: single-pass profile, history overwrite guard, and atomic output (BCPACK-TOOL-HARDENING) #1422
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1422"
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 IlyassRS3 on 2026-11-24T23:51:12Z.
Item ID:
BCPACK-TOOL-HARDENINGAI-assisted: yes
Summary
Fixes five bugs in
tools/bcpack_tool.py:profile_stream():profile_stream()previously calledinspect_stream()and then calledbcpack.decode_lanes()a second time on the same input. Extracted_inspect_decoded_lanes()so bothinspect_stream()andprofile_stream()decode the bitstream exactly once.--historyindecode_file():decode_file()guardedin_pathviasame_report_path, but allowedout_pathto overwrite a--historyJSON file (directly or via symlink/hardlink/case-folded alias) or the per-codec<history_dir>/<codec>.jsonfile read bybcpack_tables_bptc. Both are now protected viasame_report_path(while preservingdicthistory support for Python API callers).--historyerror attribution for directories with a trailing slash:os.path.basename("/path/to/hist_dir/")returns"", and"" not in str(e)was alwaysFalse, silently dropping filename attribution onjson.JSONDecodeError._history_paths()normalizes the directory path and resolves to the concrete<codec>.jsonfile when present so errors always name the failing history file.decode_file()now rejects symlink cycles (ELOOP) and existing directories (IsADirectoryError) before reading/decoding, preserves symlinks by resolvingos.path.realpath(out_path)(matchingtools/glb_inspect.py), stages regular-file writes throughtempfile.NamedTemporaryFile+file_mode.published_mode+os.replace, and cleans up staged files on failure so existing output bytes are never truncated on partial write errors.bcpack.BcpackUnsupportedCodecand redirected stdout cleanly in CLI:main()now catchesbcpack.BcpackUnsupportedCodec(NotImplementedError) alongside(ValueError, OSError)so it emits oneERROR:line and exits 2 instead of printing a traceback, and guardssys.stdout.reconfigure(errors="replace").Verification (macOS Apple M5, arm64, Python 3.14; no game files)
python3 -m compileall -q make_game.py tools tests— OKpython3 -I scripts/check_no_game_data.py tools/bcpack_tool.py tests/test_bcpack_tool.py— OKpython3 -I tests/test_bcpack_tool.py -v— 28/28 OK (10 new regression tests)python3 -I tests/test_bcpack.py— 20/20 OKpython3 -I tests/test_bcpack_tables.py— 34/34 OKpython3 -I tests/test_bcpack_tables_bptc.py— 21/21 OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OKpython3 -I tests/test_ci_registration.py— 16/16 OKtests/test_bcpack_tool.pyagainst unpatchedupstream/main364ab4eab):FAILED (failures=6, errors=1)— catches doubledecode_lanes, overwriting--historyfile / symlink /<dir>/bc1.json, dropped trailing-slash history attribution, non-atomic overwrite, and uncaughtBcpackUnsupportedCodec.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T23:51:27Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:15:09Z.
Red/green: On main test_bcpack_tool.py has 5 failures and 1 error (an unsupported codec raises a traceback instead of exiting with code 2), and with the PR 28 tests pass (4 skipped) on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:50:19Z.
Verified by OreoFR
3408969a7+ PR heade1fd5654epython -I tests/test_bcpack_tool.pyAI-assisted (Claude Code, Claude Opus 5.5).