mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:50:52 +01:00
[PR #1422] bcpack_tool: single-pass profile, history overwrite guard, and atomic output (BCPACK-TOOL-HARDENING) #1451
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1451
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1422
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/bcpack-tool-hardening📝 Commits (1)
e1fd565bcpack_tool: single-pass profile, history overwrite guard, and atomic output (BCPACK-TOOL-HARDENING)📊 Changes
2 files changed (+270 additions, -15 deletions)
View changed files
📝
tests/test_bcpack_tool.py(+180 -0)📝
tools/bcpack_tool.py(+90 -15)📄 Description
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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.