tools: harden bcpack_tables_bptc.py section validation, bounds and file cache #1812
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1812
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1812/head"
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?
@kirigayakazima on GitHub · 2026-11-25 12:25 UTC · original
kirigayakazima:fix/bcpack-bptc-safety→main· +167 −58 · 2 files · 1 commits · merged 2026-11-25 17:36 UTCClaimed in the coordination issue as: BCPACK-BPTC-SECTION-AND-VALIDATION-SAFETY (#1608)
What and why
_load_json_file()intools/bcpack_tables_bptc.pyfor both_read_history_section()andload_bc_history(), keying_FILE_CACHEbyos.path.realpathand(st_mtime_ns, st_size, st_dev, st_ino)so same-size, same-mtime atomic file replacements invalidate cleanly, and translatingRecursionErrortoValueError.{"bc6h": []},{"bc7": "bad"}) withValueErrorin_read_history_section()instead of failing later withAttributeError.list/tuple) inload_bc6h()(endpointHistory,indexHistory,endpointConfirmedBits,indexConfirmedBits) and inload_bc7()(historyEndpointLow2Fits,historyEndpointLastResort) so scalar rows raiseValueErrorinstead ofTypeError.ep_cb[k][field](0 <= cb <= 8) before computing8 - max(depth, cb)inhistoryEndpointLow2Fits(avoiding negative shift counts), and validate all indices inhistoryEndpointLastResort.tests/test_bcpack_tables_bptc.py.Tested
python -I tests/test_bcpack_tables_bptc.py -v->Ran 27 tests in 0.077s,OK(verified in a detachedupstream/mainworktree that all six new tests fail before the fix:FAILED (failures=8, errors=11)).test_bcpack.py,test_bcpack_history_calib.py,test_bcpack_native.py(skipped=12),test_bcpack_tables.py, andtest_bcpack_tool.py-> exit0.python -I tests/test_ci_registration.py->Ran 16 tests in 4.487s,OK.python -I tests/test_text_write_line_endings.py->Ran 3 tests in 12.675s,OK.python -I scripts/check_no_game_data.py tools/bcpack_tables_bptc.py tests/test_bcpack_tables_bptc.py-> exit0.python -I -m compileall -q tools/bcpack_tables_bptc.py tests/test_bcpack_tables_bptc.pyandgit diff --check-> clean.GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)
AI-assisted: yes
Checklist
needs rebase).@madvillain91 on GitHub · 2026-11-25 13:19 UTC · original · reviewed
Independent Windows 11 26H2 (26300.9711) check at
81e34a569against main384abe5b0(PR base0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. All 46 tests passed across test_bcpack_tables_bptc.py (27/27 in 0.195s), test_ci_registration.py (16/16 in 7.738s), and test_text_write_line_endings.py (3/3 in 15.670s), with check_no_game_data.py and compileall clean. Verified realpath + (st_mtime_ns, st_size, st_dev, st_ino) cache invalidation on Windows NTFS same-size/same-mtime os.replace, non-dict/scalar/bounds validation, RecursionError -> ValueError conversion, and BC7 confirmed-bits <= 8 guard preventing negative shifts. LGTM.@DeadlyChirp on GitHub · 2026-11-25 15:48 UTC · original
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
python -m pytest -q tests/test_bcpack_tables_bptc.py:(AI-assisted test run; output checked by hand.)
@aslan2142 on GitHub · 2026-11-25 17:36 UTC · original
Merged. Thank you, @kirigayakazima. Section validation, bounds and file handling are hardened.
mainand pass here; the docs, line-ending and CI/ctest registration checks pass, and so does the game-data check.main360c728bd+81e34a569: the semantic suite passes (490 files, 6,292 tests, 0 files failed);test_bcpack_tables_bptcpass; the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 2 changed files.AI-assisted (Claude Code, Claude Opus 5.5).