[PR #5077] [MERGED] Load a region chunk whatever follows its root (#5064, point 6) #6045

Closed
opened 2026-11-03 05:16:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5077
Author: @k3yh
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/region-chunk-trailing-bytes


📝 Commits (1)

  • a921e7b Load a region chunk whatever follows its root (#5064)

📊 Changes

3 files changed (+103 additions, -23 deletions)

View changed files

📝 crates/horizon-world/src/compression.rs (+37 -17)
📝 crates/horizon-world/src/region.rs (+8 -6)
📝 crates/horizon-world/tests/world_io.rs (+58 -0)

📄 Description

🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally.

What and why

Refs #5064, point 6 only. The other seven points are not touched here.

Some region chunk records have bytes after the NBT root, or a damaged compressed stream past it. Vanilla loads such a chunk. Horizon failed to load it, SaveDir::read_record took the chunk as missing, and the game generated the chunk again and saved it over what had been built there.

Vanilla's RegionFileStorage.read calls NbtIo.read(DataInput) on RegionFile.getChunkDataInputStream and closes the stream (26.3 bytecode, javap). It reads only as far as the root ends: no trailing-bytes check, and the inflater never reaches a damaged tail. Horizon's ChunkRecord::nbt decompressed the whole record first, failing on a damaged tail, then rejected any bytes after the root ("trailing bytes after region chunk NBT").

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Change

  • Compression::decode_into is decode writing into a buffer that keeps whatever was decoded before an error, as a stream reader would already have handed it out. decode calls it, so every other caller behaves as before.
  • An LZ4 block reaches the buffer only once it has decoded and its checksum matches, because lz4-java's LZ4BlockInputStream hands out whole checked blocks.
  • ChunkRecord::nbt parses the root from that buffer and ignores what follows. If the root can't be parsed, it returns the decompression error, or else the NBT error, so a root cut short still fails.

Vanilla reference

  • RegionFileStorage.read(ChunkPos): getChunkDataInputStream, then NbtIo.read(DataInput), then close.
  • RegionFile.getChunkDataInputStream / RegionFileVersion (InflaterInputStream, GZIPInputStream, LZ4BlockInputStream).

Test

horizon-world/tests/world_io.rs::a_chunk_loads_whatever_follows_its_root:

  • The root loads in five cases: uncompressed with a byte after it, zlib with junk after, gzip with junk after, zlib with a corrupted Adler-32, and LZ4 with the second block's checksum broken (the root sits in the first block).
  • A zlib record whose root is cut short still errors.
  • On main the test fails with "trailing bytes after region chunk NBT". It passes here. All 317 horizon-world tests pass.

Against vanilla classes:

  • Setup: four r.0.0.mca files, read with 26.3's own RegionFileStorage.read (a small Java program on the 26.3 jar, after Bootstrap.bootStrap()) and with Horizon's RegionFile::read + ChunkRecord::nbt.
record vanilla 26.3 main this branch
valid zlib (control) {x:7} {x:7} {x:7}
point 6's repro (uncompressed, ff after the root) {} trailing bytes after region chunk NBT {}
zlib, junk after the root {x:7} trailing bytes after region chunk NBT {x:7}
zlib, damaged tail {x:7} deflate decompression error: incorrect data check {x:7}

In game (single player, Windows):

  • Setup: a test world with a hand-built pit in chunk (10, 9). I appended 19 junk bytes after that chunk's root and wrote it back as zlib. Each run used its own copy of the world.
  • Check: count the non-air blocks in x 160–175, y 60–75, z 144–159 (horizon-ctl blocks). On vanilla a data pack checks 32 points in the same box.
air in the box (of 4096)
world before the damage, nightly 1da354b 4018 (the pit)
damaged, nightly 1da354b 1352: stone 2206, sand, dirt, sandstone (the chunk was generated again)
damaged, this branch 4018, same as before the damage
damaged, vanilla Java 26.3 32 of 32 points air. Same check on the world the nightly regenerated: 0 of 32

Not checked: the other points of #5064. Not checked either: a damaged gzip tail beyond the unit test, and LAN or a dedicated server. They use the same SaveDir path.

Self-check

pr_ready (tools/pr_ready.py --quick --base 13ce6bcc6 on DESKTOP-S9O4938, against 13ce6bcc6 at 13ce6bcc6, 3 min 13 s)

Check Result
Scope ✅ 3 files, +103 −23
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 495 run, FAILED (errors=2, skipped=1) (48 s)
rustfmt ✅ (7 s)
clippy ✅ (52 s)
tests: horizon-world ✅ 317 passed (1 min 22 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The two Python errors come from files this PR doesn't touch, and both also failed on main on this machine:

  • test_port_ledger cannot import tests.test_class_index.
  • test_perf_bench's windows_version() gets nothing from cmd /C ver on a Spanish Windows.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5077 **Author:** [@k3yh](https://github.com/k3yh) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/region-chunk-trailing-bytes` --- ### 📝 Commits (1) - [`a921e7b`](https://github.com/horizon-rust/horizon/commit/a921e7b79ea22cfff2aa36a24987e5b878fa574d) Load a region chunk whatever follows its root (#5064) ### 📊 Changes **3 files changed** (+103 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/compression.rs` (+37 -17) 📝 `crates/horizon-world/src/region.rs` (+8 -6) 📝 `crates/horizon-world/tests/world_io.rs` (+58 -0) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why Refs #5064, point 6 only. The other seven points are not touched here. Some region chunk records have bytes after the NBT root, or a damaged compressed stream past it. Vanilla loads such a chunk. Horizon failed to load it, `SaveDir::read_record` took the chunk as missing, and the game generated the chunk again and saved it over what had been built there. Vanilla's `RegionFileStorage.read` calls `NbtIo.read(DataInput)` on `RegionFile.getChunkDataInputStream` and closes the stream (26.3 bytecode, `javap`). It reads only as far as the root ends: no trailing-bytes check, and the inflater never reaches a damaged tail. Horizon's `ChunkRecord::nbt` decompressed the whole record first, failing on a damaged tail, then rejected any bytes after the root ("trailing bytes after region chunk NBT"). ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Change - `Compression::decode_into` is `decode` writing into a buffer that keeps whatever was decoded before an error, as a stream reader would already have handed it out. `decode` calls it, so every other caller behaves as before. - An LZ4 block reaches the buffer only once it has decoded and its checksum matches, because lz4-java's `LZ4BlockInputStream` hands out whole checked blocks. - `ChunkRecord::nbt` parses the root from that buffer and ignores what follows. If the root can't be parsed, it returns the decompression error, or else the NBT error, so a root cut short still fails. ## Vanilla reference - `RegionFileStorage.read(ChunkPos)`: `getChunkDataInputStream`, then `NbtIo.read(DataInput)`, then close. - `RegionFile.getChunkDataInputStream` / `RegionFileVersion` (`InflaterInputStream`, `GZIPInputStream`, `LZ4BlockInputStream`). ## Test `horizon-world/tests/world_io.rs::a_chunk_loads_whatever_follows_its_root`: - The root loads in five cases: uncompressed with a byte after it, zlib with junk after, gzip with junk after, zlib with a corrupted Adler-32, and LZ4 with the second block's checksum broken (the root sits in the first block). - A zlib record whose root is cut short still errors. - On main the test fails with "trailing bytes after region chunk NBT". It passes here. All 317 `horizon-world` tests pass. **Against vanilla classes:** - Setup: four `r.0.0.mca` files, read with 26.3's own `RegionFileStorage.read` (a small Java program on the 26.3 jar, after `Bootstrap.bootStrap()`) and with Horizon's `RegionFile::read` + `ChunkRecord::nbt`. | record | vanilla 26.3 | main | this branch | |---|---|---|---| | valid zlib (control) | `{x:7}` | `{x:7}` | `{x:7}` | | point 6's repro (uncompressed, `ff` after the root) | `{}` | trailing bytes after region chunk NBT | `{}` | | zlib, junk after the root | `{x:7}` | trailing bytes after region chunk NBT | `{x:7}` | | zlib, damaged tail | `{x:7}` | deflate decompression error: incorrect data check | `{x:7}` | **In game** (single player, Windows): - Setup: a test world with a hand-built pit in chunk (10, 9). I appended 19 junk bytes after that chunk's root and wrote it back as zlib. Each run used its own copy of the world. - Check: count the non-air blocks in x 160–175, y 60–75, z 144–159 (`horizon-ctl blocks`). On vanilla a data pack checks 32 points in the same box. | | air in the box (of 4096) | |---|---| | world before the damage, nightly 1da354b | 4018 (the pit) | | damaged, nightly 1da354b | **1352**: stone 2206, sand, dirt, sandstone (the chunk was generated again) | | damaged, this branch | **4018**, same as before the damage | | damaged, vanilla Java 26.3 | 32 of 32 points air. Same check on the world the nightly regenerated: 0 of 32 | Not checked: the other points of #5064. Not checked either: a damaged gzip tail beyond the unit test, and LAN or a dedicated server. They use the same `SaveDir` path. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base 13ce6bcc6` on DESKTOP-S9O4938, against 13ce6bcc6 at 13ce6bcc6, 3 min 13 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +103 −23 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 495 run, FAILED (errors=2, skipped=1) (48 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (52 s) | | tests: horizon-world | ✅ 317 passed (1 min 22 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The two Python errors come from files this PR doesn't touch, and both also failed on main on this machine: - `test_port_ledger` cannot import `tests.test_class_index`. - `test_perf_bench`'s `windows_version()` gets nothing from `cmd /C ver` on a Spanish Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6045
No description provided.