[PR #5085] [MERGED] Write a string too long for modified UTF-8 empty on disk (#5064, point 5) #6052

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

📋 Pull Request Information

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

Base: main ← Head: fix/nbt-long-string-save


📝 Commits (3)

  • d516b77 Write a string too long for modified UTF-8 empty on disk (#5064)
  • 78e2882 Merge origin/main into fix/long-string-disk-write
  • 0aa1e5e Merge origin/main into fix/nbt-long-string-save

📊 Changes

1 file changed (+44 additions, -2 deletions)

View changed files

📝 crates/horizon-world/src/nbt.rs (+44 -2)

📄 Description

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

What and why

Refs #5064, point 5 only. Point 6 is #5077; the other points are not touched.

Vanilla's disk NBT writer, NbtIo.write(CompoundTag, DataOutput), goes through writeUnnamedTagWithFallback, which wraps the output in NbtIo$StringFallbackDataOutput. That wrapper catches UTFDataFormatException from writeUTF, logs "Failed to write NBT String", and writes "" instead. The rest of the tree is written. RegionFileStorage.write saves chunks through NbtIo.write. I checked all of this in the 26.3 bytecode with javap. Vanilla's network path (writeAnyTag) has no fallback and throws.

Horizon's nbt::write_named returned an error instead. That matters more than the issue says: write_region_records encodes a save batch before writing any of it (let record = record?). So one block entity with such a string makes the whole batch fail, and every chunk changed since the last save is lost, not only the one with the string. In game, the integrated server also shuts down with "failed to write region files: NBT at byte 1555: modified UTF-8 exceeds 65535 bytes".

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: Writer gets empty_long_strings. write_named, the disk writer, sets it and writes a string over 65535 encoded bytes as an empty string, the value or the key alike, as vanilla's writeUTF fallback does. write_network leaves it off and still refuses. Vanilla also logs "Failed to write NBT String". horizon-world has no logger, so that line is left out; it is marked as a shortcut: in the code.

Every write_named caller writes a file: regions, level.dat, structure templates, game rules, scoreboard, servers.dat, the datafix tool and mod tables. Vanilla writes all of those through NbtIo.write or writeCompressed.

Vanilla reference

  • NbtIo.write(CompoundTag, DataOutput) → writeUnnamedTagWithFallback → NbtIo$StringFallbackDataOutput.writeUTF.
  • RegionFileStorage.write(ChunkPos, CompoundTag) → NbtIo.write.
  • NbtIo.writeAnyTag (network) has no fallback.

Test

nbt::tests::the_disk_writer_empties_a_string_too_long_for_modified_utf8:

  • write_named of {s: 32768 × U+0000} gives vanilla 26.3's exact bytes 0a 0000 08 0001 73 0000 00. I got those with a small Java program calling NbtIo.write on the 26.3 jar.
  • write_network still errors, as NbtIo.writeAnyTag does in that program (UTFDataFormatException: … too long: 65536 bytes).
  • {before, long, after} reads back with before and after intact and long empty.
  • Fails on main ("modified UTF-8 exceeds 65535 bytes") and passes here. All horizon-world tests pass.

In game (single player, Windows):

  • Each run used its own copy of a test world.
  • In one session: a diamond block at 166 61 150, an emerald block in another chunk at 182 61 150, and a command block at 165 61 150 whose Command is 22000 × U+4E2D (66000 bytes).
  • Then save, quit, open again and look at the three blocks.
save diamond (same chunk) emerald (other chunk) command block
nightly 1da354b error: modified UTF-8 exceeds 65535 bytes lost lost lost
this branch ok kept kept kept, Command: ""
vanilla Java 26.3 logs "Failed to write NBT String" kept kept kept, Command: ""

Vanilla was driven by a data pack, and closed through its window's close message so it saved.

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

Self-check

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

Check Result
Scope ✅ 1 files, +44 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 495 run, FAILED (errors=2, skipped=1) (47 s)
rustfmt ✅ (7 s)
clippy ✅ (52 s)
tests: horizon-world ✅ 317 passed (1 min 20 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/5085 **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-long-string-save` --- ### 📝 Commits (3) - [`d516b77`](https://github.com/horizon-rust/horizon/commit/d516b77daa43b14f150d02fbabcd0ea5873cf81b) Write a string too long for modified UTF-8 empty on disk (#5064) - [`78e2882`](https://github.com/horizon-rust/horizon/commit/78e288212a24fd8d83dd616a2ad68b0473fbcd82) Merge origin/main into fix/long-string-disk-write - [`0aa1e5e`](https://github.com/horizon-rust/horizon/commit/0aa1e5e37c7d3a0562f95cf771b32fe28732e189) Merge origin/main into fix/nbt-long-string-save ### 📊 Changes **1 file changed** (+44 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/nbt.rs` (+44 -2) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why Refs #5064, point 5 only. Point 6 is #5077; the other points are not touched. Vanilla's disk NBT writer, `NbtIo.write(CompoundTag, DataOutput)`, goes through `writeUnnamedTagWithFallback`, which wraps the output in `NbtIo$StringFallbackDataOutput`. That wrapper catches `UTFDataFormatException` from `writeUTF`, logs "Failed to write NBT String", and writes `""` instead. The rest of the tree is written. `RegionFileStorage.write` saves chunks through `NbtIo.write`. I checked all of this in the 26.3 bytecode with `javap`. Vanilla's network path (`writeAnyTag`) has no fallback and throws. Horizon's `nbt::write_named` returned an error instead. That matters more than the issue says: `write_region_records` encodes a save batch before writing any of it (`let record = record?`). So one block entity with such a string makes the whole batch fail, and **every chunk changed since the last save is lost**, not only the one with the string. In game, the integrated server also shuts down with "failed to write region files: NBT at byte 1555: modified UTF-8 exceeds 65535 bytes". ## 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`: `Writer` gets `empty_long_strings`. `write_named`, the disk writer, sets it and writes a string over 65535 encoded bytes as an empty string, the value or the key alike, as vanilla's `writeUTF` fallback does. `write_network` leaves it off and still refuses. Vanilla also logs "Failed to write NBT String". `horizon-world` has no logger, so that line is left out; it is marked as a `shortcut:` in the code. Every `write_named` caller writes a file: regions, `level.dat`, structure templates, game rules, scoreboard, `servers.dat`, the datafix tool and mod tables. Vanilla writes all of those through `NbtIo.write` or `writeCompressed`. ## Vanilla reference - `NbtIo.write(CompoundTag, DataOutput)` → `writeUnnamedTagWithFallback` → `NbtIo$StringFallbackDataOutput.writeUTF`. - `RegionFileStorage.write(ChunkPos, CompoundTag)` → `NbtIo.write`. - `NbtIo.writeAnyTag` (network) has no fallback. ## Test `nbt::tests::the_disk_writer_empties_a_string_too_long_for_modified_utf8`: - `write_named` of `{s: 32768 × U+0000}` gives vanilla 26.3's exact bytes `0a 0000 08 0001 73 0000 00`. I got those with a small Java program calling `NbtIo.write` on the 26.3 jar. - `write_network` still errors, as `NbtIo.writeAnyTag` does in that program (`UTFDataFormatException: … too long: 65536 bytes`). - `{before, long, after}` reads back with `before` and `after` intact and `long` empty. - Fails on main ("modified UTF-8 exceeds 65535 bytes") and passes here. All `horizon-world` tests pass. **In game** (single player, Windows): - Each run used its own copy of a test world. - In one session: a diamond block at 166 61 150, an emerald block in another chunk at 182 61 150, and a command block at 165 61 150 whose `Command` is 22000 × U+4E2D (66000 bytes). - Then save, quit, open again and look at the three blocks. | | save | diamond (same chunk) | emerald (other chunk) | command block | |---|---|---|---|---| | nightly 1da354b | error: modified UTF-8 exceeds 65535 bytes | **lost** | **lost** | **lost** | | this branch | ok | kept | kept | kept, `Command: ""` | | vanilla Java 26.3 | logs "Failed to write NBT String" | kept | kept | kept, `Command: ""` | Vanilla was driven by a data pack, and closed through its window's close message so it saved. Not checked: the other points of #5064, and LAN or a dedicated server. They save through the same `write_named`. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base 13ce6bcc6` on DESKTOP-S9O4938, against 13ce6bcc6 at 13ce6bcc6, 3 min 9 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +44 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 495 run, FAILED (errors=2, skipped=1) (47 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (52 s) | | tests: horizon-world | ✅ 317 passed (1 min 20 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:53 +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#6052
No description provided.