[PR #5090] [MERGED] Skip a file root's name unread, as vanilla does (#5064, point 3) #6069

Closed
opened 2026-11-03 06:11:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/nbt-root-name


📝 Commits (1)

  • 83df596 Skip a file root's name unread, as vanilla does (#5064)

📊 Changes

1 file changed (+67 additions, -30 deletions)

View changed files

📝 crates/horizon-world/src/nbt.rs (+67 -30)

📄 Description

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

What and why

Refs #5064, point 3 only. Points 5 and 6 are in #5085 and #5077. Points 1, 2, 4, 7 and 8 are not touched.

Vanilla's NbtIo.readUnnamedTag reads the root's type byte and then calls StringTag.skipString, which skips the root's name without decoding it. I checked this in the 26.3 bytecode with javap. So a file whose root name isn't modified UTF-8 still loads. Horizon's read_named decoded the name and refused the whole file.

For level.dat this loses data. Horizon's nightly opened such a world with fresh defaults and saved them over the real ones: the game mode, the cheats setting and the time reset. Vanilla opens the same file with all of it intact.

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

nbt.rs:

  • The modified UTF-8 decoding moves out of Reader::string into modified_utf8(&[u8]) -> Option<JavaString>. The decoding is unchanged.
  • The new Reader::root_name takes the name's bytes and reads a name that isn't modified UTF-8 as empty.
  • read_named and read_named_streaming use root_name. Every other string, compound keys included, still goes through string and is refused when invalid, as DataInput.readUTF refuses it.
  • A name cut short still fails, as it does in vanilla: skipBytes stops at the end of the input and the payload read fails.

Vanilla's writer always writes the root name empty (writeUnnamedTag). Horizon writes back the name it read, so a valid name is kept as before.

Vanilla reference

  • NbtIo.read(DataInput, NbtAccounter) → readUnnamedTag: readByte, then StringTag.skipString, then readTagSafe.
  • NbtIo.writeUnnamedTag.

Test

nbt::tests::a_root_name_that_is_not_modified_utf8_is_skipped. I ran each case through NbtIo.read from a small Java program on the 26.3 jar:

bytes vanilla 26.3 main this branch
0a0002ffff00 (the issue's repro) {}, 6 bytes invalid Java modified UTF-8 {}, 6 bytes
0a0002ffff030001780000000700 {x:7} invalid Java modified UTF-8 {x:7}
0a00047465737400 (valid name "test") {} {}, name "test" {}, name "test"
0a0009ff (name cut short) error error error
0a000003000278ff0000000700 (a key that isn't modified UTF-8) error error error

The test fails on main and passes here. All horizon-world tests pass, and so do horizon-protocol's servers tests, which read servers.dat's root name.

In game (single player, Windows):

  • Setup: the test world's level.dat with its root name replaced by ff ff and its level.dat_old removed. Each run used its own copy.
  • Each game opened the world, then I read level.dat again after it closed.
opens game mode cheats time
before the damage creative on 16910
nightly 1da354b yes, with fresh defaults saved over the file survival off 105
this branch yes creative on 17028 (carried on)
vanilla Java 26.3 yes creative on 17055 (carried on)

This branch and vanilla both save the root name back empty (0a 0000 …). The pit built in that world's chunks was intact in all three, since the chunks are in other files.

Overlap with #5085 (point 5, also mine): both add a test at the top of nbt.rs's test module, so whichever merges second has a conflict there. The fix is to keep both tests, and I'll rebase whichever is left. The code changes don't overlap: this PR touches the reader, #5085 the writer.

Not checked: the other points of #5064, and LAN or a dedicated server. They read files through the same read_named.

Self-check

pr_ready (tools/pr_ready.py --quick --base c3905131b on DESKTOP-S9O4938, against c3905131b at c3905131b, 2 min 17 s)

Check Result
Scope ✅ 1 files, +67 −30
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 495 run, FAILED (errors=2, skipped=1) (47 s)
rustfmt ✅ (7 s)
clippy ✅ (15 s)
tests: horizon-world ✅ 317 passed (1 min 4 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/5090 **Author:** [@k3yh](https://github.com/k3yh) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/nbt-root-name` --- ### 📝 Commits (1) - [`83df596`](https://github.com/horizon-rust/horizon/commit/83df5969b8d012c14a54d3490c6a4016562bff36) Skip a file root's name unread, as vanilla does (#5064) ### 📊 Changes **1 file changed** (+67 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/nbt.rs` (+67 -30) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why Refs #5064, point 3 only. Points 5 and 6 are in #5085 and #5077. Points 1, 2, 4, 7 and 8 are not touched. Vanilla's `NbtIo.readUnnamedTag` reads the root's type byte and then calls `StringTag.skipString`, which skips the root's name without decoding it. I checked this in the 26.3 bytecode with `javap`. So a file whose root name isn't modified UTF-8 still loads. Horizon's `read_named` decoded the name and refused the whole file. For `level.dat` this loses data. Horizon's nightly opened such a world with fresh defaults and saved them over the real ones: the game mode, the cheats setting and the time reset. Vanilla opens the same file with all of it intact. ## 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 `nbt.rs`: - The modified UTF-8 decoding moves out of `Reader::string` into `modified_utf8(&[u8]) -> Option<JavaString>`. The decoding is unchanged. - The new `Reader::root_name` takes the name's bytes and reads a name that isn't modified UTF-8 as empty. - `read_named` and `read_named_streaming` use `root_name`. Every other string, compound keys included, still goes through `string` and is refused when invalid, as `DataInput.readUTF` refuses it. - A name cut short still fails, as it does in vanilla: `skipBytes` stops at the end of the input and the payload read fails. Vanilla's writer always writes the root name empty (`writeUnnamedTag`). Horizon writes back the name it read, so a valid name is kept as before. ## Vanilla reference - `NbtIo.read(DataInput, NbtAccounter)` → `readUnnamedTag`: `readByte`, then `StringTag.skipString`, then `readTagSafe`. - `NbtIo.writeUnnamedTag`. ## Test `nbt::tests::a_root_name_that_is_not_modified_utf8_is_skipped`. I ran each case through `NbtIo.read` from a small Java program on the 26.3 jar: | bytes | vanilla 26.3 | main | this branch | |---|---|---|---| | `0a0002ffff00` (the issue's repro) | `{}`, 6 bytes | invalid Java modified UTF-8 | `{}`, 6 bytes | | `0a0002ffff030001780000000700` | `{x:7}` | invalid Java modified UTF-8 | `{x:7}` | | `0a00047465737400` (valid name "test") | `{}` | `{}`, name "test" | `{}`, name "test" | | `0a0009ff` (name cut short) | error | error | error | | `0a000003000278ff0000000700` (a key that isn't modified UTF-8) | error | error | error | The test fails on main and passes here. All `horizon-world` tests pass, and so do `horizon-protocol`'s `servers` tests, which read `servers.dat`'s root name. **In game** (single player, Windows): - Setup: the test world's `level.dat` with its root name replaced by `ff ff` and its `level.dat_old` removed. Each run used its own copy. - Each game opened the world, then I read `level.dat` again after it closed. | | opens | game mode | cheats | time | |---|---|---|---|---| | before the damage | | creative | on | 16910 | | nightly 1da354b | yes, with **fresh defaults saved over the file** | **survival** | **off** | **105** | | this branch | yes | creative | on | 17028 (carried on) | | vanilla Java 26.3 | yes | creative | on | 17055 (carried on) | This branch and vanilla both save the root name back empty (`0a 0000 …`). The pit built in that world's chunks was intact in all three, since the chunks are in other files. Overlap with #5085 (point 5, also mine): both add a test at the top of `nbt.rs`'s test module, so whichever merges second has a conflict there. The fix is to keep both tests, and I'll rebase whichever is left. The code changes don't overlap: this PR touches the reader, #5085 the writer. Not checked: the other points of #5064, and LAN or a dedicated server. They read files through the same `read_named`. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base c3905131b` on DESKTOP-S9O4938, against c3905131b at c3905131b, 2 min 17 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +67 −30 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 495 run, FAILED (errors=2, skipped=1) (47 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (15 s) | | tests: horizon-world | ✅ 317 passed (1 min 4 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 06:11:23 +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#6069
No description provided.