Fix garbage prop-batch instances (pool refs first, separate graphics page stream) #48

Manually merged
github merged 1 commit from gh-pr/48/head into gh-pr/48/base 2026-11-26 20:05:43 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-23 13:57 UTC · original
holdmysocks:fix/prop-batch-decode → master · +258 −8 · 6 files · 1 commits · merged 2026-11-23 14:02 UTC

About 0.5% of prop-batch instances in levels and 10% in pack/shared_minigame000 decoded with garbage transforms: position 0,0,0 or 1e10–1e35, and scale 0, 1e3–1e18 or inf. This had two causes.

1. Pool references read as real pointers (meta7a.rs)

Meta::ptr tried the real sys/gfx pointer reading first. A pool reference whose byte offset is 0x500–0x5FF or 0x600–0x6FF, with a zero low byte, also looks like a pointer. For example, 0x5000_0003 is block 3, offset 0x500, but it reads as sys offset 3. Pool references now resolve first, and the real-pointer reading is only the fallback.

Census of every pointer, array and map member in every levels meta resource: no value needs the real reading. All 14,471 ambiguous values point into a block of the expected struct, and none of them lands on a block start as a real pointer. Besides prop batches (8,617 arrays), this also fixes about 950 CEntityDef extension arrays and about 4,500 other arrays. sixng lights levels: 136,548 → 139,291 light sets and 775,132 → 778,985 placed lights, with 0 implausible positions before or after.

2. Graphics page in its own stream (resource.rs)

In 105 map files in levels and 2 in the minigame pack, the last stream fills whole 64 KiB chunks (64 K, 128 K or 448 K). In those files the graphics page isn't stored uncompressed right after that stream. It is a separate zlib stream a few KiB further on, which the index lists as a separate bin entry. Its length is exactly the instance block extent, or that rounded up to 64 KiB. load_meta now searches 256 KiB past the last stream, at 16-byte alignment, for such a stream. It only searches in the full-chunk case: without that limit, tiny 64-byte pages matched unrelated streams.

Numbers (sixng placements --batches-only, batch_props.bin)

Bad means a non-finite value, |pos| ≥ 1e10, pos all zero, or a scale axis of 0, ≥ 1e3 or inf.

archive records bad before bad after
levels 24.88 M (707,399 prop batches) 130,066 in 23,352 batches 0
shared_minigame000 57,545 (3,317 prop batches) 5,728 in 923 batches 0

A stricter research check (examples/propbad.rs, which also flags any scale axis below 1e-4) still flags 6 records. All 6 are real data: flat props with a z scale of exactly 1e-5, inside their batch bbox, with a sensible rotation.

Tests

  • batches::tests: a synthetic batch at the ambiguous pool reference 0x5000_0003, with decoy bytes where the real-pointer reading lands. Also checks the gfx-offset variant and the fallback to a real pointer.
  • resource::page_stream_tests: a page stream behind junk and an unrelated stream, a page padded to 64 KiB, and lengths that are too small or too large.

The README batch section notes the fix and that batch_props.bin exports from before it should be redone.

**@⁠holdmysocks** on GitHub · 2026-11-23 13:57 UTC · [original](https://github.com/holdmysocks/SixNG/pull/48) `holdmysocks:fix/prop-batch-decode` → `master` · +258 −8 · 6 files · 1 commits · merged 2026-11-23 14:02 UTC About 0.5% of prop-batch instances in `levels` and 10% in `pack/shared_minigame000` decoded with garbage transforms: position 0,0,0 or 1e10–1e35, and scale 0, 1e3–1e18 or inf. This had two causes. ## 1. Pool references read as real pointers (`meta7a.rs`) `Meta::ptr` tried the real sys/gfx pointer reading first. A pool reference whose byte offset is 0x500–0x5FF or 0x600–0x6FF, with a zero low byte, also looks like a pointer. For example, `0x5000_0003` is block 3, offset 0x500, but it reads as sys offset 3. Pool references now resolve first, and the real-pointer reading is only the fallback. Census of every pointer, array and map member in every `levels` meta resource: no value needs the real reading. All 14,471 ambiguous values point into a block of the expected struct, and none of them lands on a block start as a real pointer. Besides prop batches (8,617 arrays), this also fixes about 950 `CEntityDef` extension arrays and about 4,500 other arrays. `sixng lights levels`: 136,548 → 139,291 light sets and 775,132 → 778,985 placed lights, with 0 implausible positions before or after. ## 2. Graphics page in its own stream (`resource.rs`) In 105 map files in `levels` and 2 in the minigame pack, the last stream fills whole 64 KiB chunks (64 K, 128 K or 448 K). In those files the graphics page isn't stored uncompressed right after that stream. It is a separate zlib stream a few KiB further on, which the index lists as a separate `bin` entry. Its length is exactly the instance block extent, or that rounded up to 64 KiB. `load_meta` now searches 256 KiB past the last stream, at 16-byte alignment, for such a stream. It only searches in the full-chunk case: without that limit, tiny 64-byte pages matched unrelated streams. ## Numbers (`sixng placements --batches-only`, `batch_props.bin`) Bad means a non-finite value, |pos| ≥ 1e10, pos all zero, or a scale axis of 0, ≥ 1e3 or inf. | archive | records | bad before | bad after | |---|---|---|---| | levels | 24.88 M (707,399 prop batches) | 130,066 in 23,352 batches | **0** | | shared_minigame000 | 57,545 (3,317 prop batches) | 5,728 in 923 batches | **0** | A stricter research check (`examples/propbad.rs`, which also flags any scale axis below 1e-4) still flags 6 records. All 6 are real data: flat props with a z scale of exactly 1e-5, inside their batch bbox, with a sensible rotation. ## Tests - `batches::tests`: a synthetic batch at the ambiguous pool reference `0x5000_0003`, with decoy bytes where the real-pointer reading lands. Also checks the gfx-offset variant and the fallback to a real pointer. - `resource::page_stream_tests`: a page stream behind junk and an unrelated stream, a page padded to 64 KiB, and lengths that are too small or too large. The README batch section notes the fix and that `batch_props.bin` exports from before it should be redone.
Two causes made 130,066 of 24.9 M prop-batch instances in levels (and
5,728 of 57,545 in the minigame pack) decode with positions of 0 or
1e10-1e35 and scales of 0, 1e3-1e18 or inf:

- Meta::ptr tried the real-pointer reading before the pool reference. A
  pool reference with a byte offset of 0x500-0x5FF or 0x600-0x6FF and a
  zero low byte (0x50000003 = block 3, offset 0x500) also reads as a sys
  or gfx pointer a few bytes into the page. Pool references now resolve
  first. In levels no pointer, array or map member needs the real reading;
  all 14,471 ambiguous values point into a block of the expected struct.
  This also fixes about 950 entity and 4,500 other extension arrays
  (lights: 775,132 -> 778,985 placed).

- When a map file's last stream fills whole 64 KiB chunks (105 files in
  levels, 2 in the minigame pack), its graphics page is not stored right
  after it but compressed as a stream of its own a few KiB further on
  (indexed as a separate bin entry). load_meta now finds the zlib stream
  that inflates to the block extent (or that rounded up to 64 KiB).

After both: 0 bad records in either archive by the same checks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:05:42 +00:00
github manually merged commit 38de2e5120 into gh-pr/48/base 2026-11-26 20:05:43 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.