Scanner: join stored (uncompressed) 64 KiB chunks into their chunked entry #221

Manually merged
github merged 1 commit from gh-pr/221/head into gh-pr/221/base 2026-11-26 20:19:17 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 23:02 UTC · original
holdmysocks:fix/raw-chunks → master · +229 −17 · 2 files · 1 commits · merged 2026-11-24 23:13 UTC

What

In a chunked entry, a 64 KiB chunk that does not compress is stored raw: exactly 65,536 bytes, no zlib header, at the next 16-byte aligned offset. The chunk after it is zlib again. The scanner only followed back-to-back zlib chunks. It stopped at the first raw chunk, so the index got a truncated entry and later a stray bin entry for the tail.

Change

  • After a zlib chunk that inflates to exactly 64 KiB, if the next aligned bytes are not a zlib stream, the scanner takes 64 KiB raw chunks (up to 8 in a row) and keeps following the entry.
  • A run is accepted only when it ends in a zlib chunk shorter than 64 KiB and no "raw" chunk contains a complete zlib stream. Otherwise the bytes are scanned as before.
  • A raw chunk is recorded as a stream whose compressed and decompressed sizes are equal (scan::is_raw). A zlib stream is always larger than its output, so the two can't be confused. read_stream / read_entry copy raw chunks as-is.
  • INDEX_VERSION 6 → 7. Segment cache file names now carry a scan version, so old segment results are not reused.
  • Unit tests: a zlib/raw mix (zlib, zlib, raw, zlib, raw, raw, short zlib) indexes as one entry and reads back byte-exact. Raw bytes with no short zlib end are not joined.

Results

The three PSO entries in packs.rpf that showed the problem now index at their full lengths:

offset before after
11dd59000 196,608 289,056
11de2e000 327,680 472,000
11de68000 196,608 272,560

Whole install (22 indexed archives), version 6 index vs version 7:

  • Entries that changed length: 43 (41 PSO, 2 bin). All of them grew, by 13,392,106 bytes in total, and every one now contains raw chunks. No entry changed without one.
  • Stray bin entries gone: 43 (2,511 → 2,468). No other entry disappeared or appeared. Total entries 1,175,601 → 1,175,558.
  • Raw chunks recognised: 88.
  • For all 41 grown PSO entries, the section sizes add up exactly to the joined length.
  • Per archive: packs 18, levels 8, story000 5, story000_script 5, data 4, anim 2, audio 1.

Workspace tests pass.

Linear: SIX-159

**@⁠holdmysocks** on GitHub · 2026-11-24 23:02 UTC · [original](https://github.com/holdmysocks/SixNG/pull/221) `holdmysocks:fix/raw-chunks` → `master` · +229 −17 · 2 files · 1 commits · merged 2026-11-24 23:13 UTC ## What In a chunked entry, a 64 KiB chunk that does not compress is stored raw: exactly 65,536 bytes, no zlib header, at the next 16-byte aligned offset. The chunk after it is zlib again. The scanner only followed back-to-back zlib chunks. It stopped at the first raw chunk, so the index got a truncated entry and later a stray `bin` entry for the tail. ## Change - After a zlib chunk that inflates to exactly 64 KiB, if the next aligned bytes are not a zlib stream, the scanner takes 64 KiB raw chunks (up to 8 in a row) and keeps following the entry. - A run is accepted only when it ends in a zlib chunk shorter than 64 KiB and no "raw" chunk contains a complete zlib stream. Otherwise the bytes are scanned as before. - A raw chunk is recorded as a stream whose compressed and decompressed sizes are equal (`scan::is_raw`). A zlib stream is always larger than its output, so the two can't be confused. `read_stream` / `read_entry` copy raw chunks as-is. - `INDEX_VERSION` 6 → 7. Segment cache file names now carry a scan version, so old segment results are not reused. - Unit tests: a zlib/raw mix (zlib, zlib, raw, zlib, raw, raw, short zlib) indexes as one entry and reads back byte-exact. Raw bytes with no short zlib end are not joined. ## Results The three PSO entries in packs.rpf that showed the problem now index at their full lengths: | offset | before | after | |---|---|---| | 11dd59000 | 196,608 | 289,056 | | 11de2e000 | 327,680 | 472,000 | | 11de68000 | 196,608 | 272,560 | Whole install (22 indexed archives), version 6 index vs version 7: - Entries that changed length: **43** (41 PSO, 2 bin). All of them grew, by 13,392,106 bytes in total, and every one now contains raw chunks. No entry changed without one. - Stray `bin` entries gone: **43** (2,511 → 2,468). No other entry disappeared or appeared. Total entries 1,175,601 → 1,175,558. - Raw chunks recognised: 88. - For all 41 grown PSO entries, the section sizes add up exactly to the joined length. - Per archive: packs 18, levels 8, story000 5, story000_script 5, data 4, anim 2, audio 1. Workspace tests pass. Linear: SIX-159
A 64 KiB chunk that does not compress is stored raw (65,536 bytes, no zlib
header) at the next 16-byte aligned offset; the chunk after it is zlib
again. Follow such runs after a full 64 KiB zlib chunk and accept them only
when they end in a shorter zlib chunk. Raw chunks are recorded as streams
with equal compressed and decompressed sizes and copied as-is by the entry
readers. Index version 7; segment caches carry a scan version.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:19:15 +00:00
github manually merged commit ce744e5fdf into gh-pr/221/base 2026-11-26 20:19:17 +00:00
Author
Owner

@⁠kaoru-maki on GitHub · 2026-11-24 23:40 UTC · original

Independent check of #221 on 11 affected entries in the dialogue pipeline (five Story, five Story Script, one audio). We reproduced all 11 extended entries and verified 20 stored chunks against the original bytes.

All nine PSIN payloads matched our earlier complete extraction byte for byte. The other two entries were DAT166. Recovered bytes restored parts of their hash tables, and all 50,885 direct wave declarations agreed with the earlier read. The check found zero additional GXT tables and zero new verified subtitle-to-stream links. The 16 hash intersections with subtitle keys remain ambiguous. Ten of those keys already had candidate streams in our catalog. Thanks for making these entries readable directly through the scanner.

**@⁠kaoru-maki** on GitHub · 2026-11-24 23:40 UTC · [original](https://github.com/holdmysocks/SixNG/pull/221#issuecomment-7147670843) Independent check of #221 on 11 affected entries in the dialogue pipeline (five Story, five Story Script, one audio). We reproduced all 11 extended entries and verified 20 stored chunks against the original bytes. All nine PSIN payloads matched our earlier complete extraction byte for byte. The other two entries were DAT166. Recovered bytes restored parts of their hash tables, and all 50,885 direct wave declarations agreed with the earlier read. The check found zero additional GXT tables and zero new verified subtitle-to-stream links. The 16 hash intersections with subtitle keys remain ambiguous. Ten of those keys already had candidate streams in our catalog. Thanks for making these entries readable directly through the scanner.
This discussion has been locked. Commenting is limited to contributors.
No description provided.