gamedata_blobs: fix unshipped count, index type checks, and atomic JSON #2258
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2258"
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 kirigayakazima on 2026-11-26T10:51:26Z.
Claimed in the coordination issue as: GAMEDATA-BLOBS-UNSHIPPED-OVERLAP-INDEX-TYPES-AND-ATOMIC-JSON (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189816855)
What and why
unshippedoverlap double-subtraction incross_reference_sgd5()(tools/gamedata_blobs.py) so preload-list entries present in bothdb0anddb1are counted accurately viasum(1 for s in stems if s not in db0_set and s not in db1_set)instead ofp["entries"] - len(in_db0) - len(in_db1).check_carve_index()to convertUnicodeDecodeErrorandRecursionErrorfromjson.load()into single-lineValueErrordiagnostics and requiretype(row.get("off")) is intandtype(row.get("stored")) is int(non-bool,>= 0).index.jsonacrossmain()andread_payloads(..., _checked_index=is_dir), reject trailing/or\--jsondirectory paths incheck_report_path()and non-file--shadersupfront beforeread_payloads(), and catchRecursionErrorcleanly inmain().--jsonoutput atomically via_write_json_atomic()(staging next toos.path.realpath(out_path), trailing LF\n,os.fsync(), preserving permissions withpublished_mode(), publishing viareplace_retry.replace(), and unlinking.blobs-*.tmpfiles on failure).GamedataBlobsSafetyTeststotests/test_gamedata_blobs.py(without overlapping#1269's lines) covering overlapunshipped,bool/negative/strindex types,RecursionError, singleindex.jsonparse, early CLI validation, and atomic JSON write/failure rollback.Tested
python -I tests/test_gamedata_blobs.py -v->Ran 14 tests in 1.178s(OK).upstream/maina73a57e1with updatedtests/test_gamedata_blobs.pycopied into detached worktree):Ran 14 tests in 1.119s(FAILED (failures=10)).python -I tests/test_ci_registration.py(Ran 16 tests in 5.560s,OK),python -I tests/test_text_write_line_endings.py(Ran 3 tests in 13.499s,OK),python -I scripts/check_no_game_data.py(exit 0),python -I -m compileall -q tools/gamedata_blobs.py tests/test_gamedata_blobs.py(exit 0),git diff --check(exit 0).GPUs tested: n/a (synthetic carve/RPF/SGD5 fixtures and atomic JSON output tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:58:27Z.
Review: COMMENTED
Windows 11: 14/14 Python tests passed. Two additional checks on a synthetic carve reproduced a missed output collision and a second
index.jsonparse. Details inline.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:58:27Z.
Code review location:
tools/gamedata_blobs.py; line 385[P2] Reject reports that would overwrite a
.bk2carve input.DirectorySource.read()reads<off>.bk2fortype: "bink2", while the delegatedgamedata_maps.check_report_path()checks only.bin. I used a single synthetic row at offset 4096 and set--jsonto the corresponding000000001000.bk2file. The CLI returned 0 and atomically replaced that input with the JSON report. Can the guard use the same filename rule asDirectorySource.read()for both payload types?Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:58:28Z.
Code review location:
tools/gamedata_blobs.py; line 446[P3] Pass the parsed index through to
DirectorySourceif the CLI should parse it once.Spying on
json.loadfor the synthetic carve shows two real reads ofindex.json._checked_indexskips another call tocheck_carve_index(), whileDirectorySource.__init__opens and parses the file again. The new test counts calls to the validator only, so it misses this second read. Reusing the validated document would also keep path validation and payload reading on the same index snapshot.Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:36:00Z.
Review: APPROVED
Approving
d1545dfde.The unshipped-count fix is real:
entries - len(in_db0) - len(in_db1)subtracted a stem present in both databases twice (it could go negative); counting stems in neither set is right. Index rows now need nonnegative integeroff/stored, bad UTF-8 is reported, the index is not checked twice, and the JSON is written atomically.Merged onto
maind1dff7949in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13.tests/test_gamedata_blobs.py: 14 passed (main: 10). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:07:05Z.
Code review location:
tools/gamedata_blobs.py; line 385Fixed:
check_report_path()now checks each row's resolved.bk2/.binpayload path matchingDirectorySource.read(), rejecting--jsondestinations that alias.bk2carve inputs. Added regression coverage intests/test_gamedata_blobs.py.Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:07:09Z.
Code review location:
tools/gamedata_blobs.py; line 446Fixed:
main()passes the already-validatedrowstoread_payloads(..., _rows=rows)using_LoadedDirectorySource, soindex.jsonis opened and parsed once cleanly. Verified viajson.loadspy intests/test_gamedata_blobs.py(15 tests OK + 5 repo checks).Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T14:23:23Z.
Review: COMMENTED
Re-checked at
843a265f4(merged ontomainec91d695c).Both earlier points are cleanly addressed:
check_report_path()now rejects.bk2and.bincarve-input aliases matchingDirectorySource.read()._LoadedDirectorySourcereuses the validated sorted rows fromcheck_carve_index()soindex.jsonis parsed once, covered by thejson.loadspy test.Verified locally on Windows 11 (Python 3):
tests/test_gamedata_blobs.py: 15/15 passedscripts/check_no_game_data.pyandgit diff --check: cleanNo remaining findings.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T09:15:35Z.
#2258 | head
843a265f47d63dec939e7f69ac1f26ebde1ae193|python3 -I tests/test_gamedata_blobs.py -v| red: 15 tests, 11 assertion failures | green: 15 passed | Red → greenBaseline assertions failed on summary counts, invalid index diagnostics and output handling.
Pinned main
4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:08:32Z.
Native Windows 11 NTFS Verification (
843a265f47)Verified
843a265f47d63dec939e7f69ac1f26ebde1ae193merged cleanly ontoorigin/main(c7753ed98a56677f10e34078b37eab0540e190ec,git merge-tree --write-treerc=0) on native Windows 11 (26200) + NTFS:origin/mainc7753ed98a):python -I tests/test_gamedata_blobs.pyfailed11/15(FAILED (failures=11)).origin/main + 843a265f47):python -I tests/test_gamedata_blobs.py:15/15 OK(overlap-safeunshippedcount, strictintrow type/sign checks,RecursionErrorhandling, singleindex.jsonparse,.bk2input-alias refusal, and pure-LF atomic JSON output).stat.S_IREADprobe: Rangamedata_blobs.main([carve, "--json", blobs.json])against a read-onlyblobs.json(stat.S_IREAD): exitedrc=1, left0.blobs-*.tmpstaged files, and preservedblobs.jsonbyte-for-byte.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:27:13Z.
Review: COMMENTED
Static audit of
843a265f4against the base code. No builds, tests, or GPU runs were performed for this review. Theunshippedcalculation counts each preload entry absent from both databases. Both index fields require exact nonnegative integers, which excludes booleans, and the validated rows are reused after one parse. The writer stages beside the resolved destination, flushes and syncs beforeos.replace, and pins LF in the form recognized bytests/test_text_write_line_endings.py. The added tests cover overlap, malformed index rows, recursion, a single parse, early argument checks, a carve-input alias, and rollback on dump and replace errors.tools/gamedata_blobs.py:430can replace a read-only report in a writable POSIX directory or turn an existing FIFO into a regular file. Preserve the nontruncating writability check for regular files and handle special destinations before the rename, as intools/bink_index.py:364.tools/gamedata_blobs.py:414turns the invalid POSIX destinationregular-file/../keep.jsonintokeep.jsonand can overwrite it. Validate the unreduced path before resolving it so an existing non-directory component still producesENOTDIR.tools/gamedata_blobs.py:433skips unlinking the stage if cleanupchmodfails. Attempt unlink independently and cover that failure path in the rollback test.tools/gamedata_blobs.py:394rejects a literal trailing backslash in a valid POSIX filename. Check separators for the active platform and update the test attests/test_gamedata_blobs.py:438.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T14:19:07Z.
Merged at head
843a265. Tested by others on this head: sodove (WSL, Python 3.14) and zmasi (Windows 11 NTFS):tests/test_gamedata_blobs.py11/15 fail on main, 15/15 pass with the PR. No GPU involved. AI-assisted: yes.