tools: harden bcpack_tables_bptc.py section validation, bounds and file cache #1812
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!1812
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bcpack-bptc-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: BCPACK-BPTC-SECTION-AND-VALIDATION-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162308818)
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).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.)
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).