[PR #2814] [MERGED] SNBT: bound nesting depth, keep nan/inf words as strings #4631

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2814
Author: @sirrayi
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix/snbt-depth-and-words


📝 Commits (2)

  • 780abb9 SNBT: bound nesting depth, keep nan/inf words as strings
  • b8f48f3 Merge remote-tracking branch 'origin/main' into upd/2814

📊 Changes

2 files changed (+208 additions, -101 deletions)

View changed files

📝 crates/horizon-client-core/src/component.rs (+102 -51)
📝 crates/horizon-world/src/nbt.rs (+106 -50)

📄 Description

🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves.

What and why

Two bugs in both SNBT parsers: horizon_world::nbt::parse_snbt and horizon_client::component::parse_snbt.

  1. Unbounded recursion. [[[[… nested deep enough overflowed the stack and aborted the whole process. The input can come from a command, a function file, a command block, or an old world being datafixed (datafix/items.rs). On a server that's a crash. Both parsers now refuse more than 512 levels (NBT's own NbtAccounter depth) with an error.
  2. nan / inf words. Rust's float parse accepts inf, infinity and nan in any case, so bare words like nand, NaNf, infd and Infinityd became floats. In text components, nan and Infinity parsed to an f64 that serde_json turns into null, so {text:nan} lost its text. Vanilla's number grammar only takes digits. A bare word with letters other than an exponent e/E (once the type suffix is removed) is now a string.

Most of the diff is re-indentation: the compound and list bodies moved into helper functions, so the depth counter goes up and down in one place.

Vanilla reference

  • NbtAccounter (512 depth) for the limit.
  • SnbtGrammar / TagParser number literals: digits, sign, ., an exponent and a type suffix.

Self-check

  • cargo fmt --all -- --check ✅
  • cargo clippy -p horizon-world -p horizon-client --lib --tests -- -D warnings ✅
  • cargo test -p horizon-world --lib (165) ✅, cargo test -p horizon-client --lib component ✅
  • New tests: nbt::tests::snbt_nesting_is_bounded, nbt::tests::snbt_bare_words_stay_strings, component::tests::snbt_nesting_is_bounded, component::tests::bare_words_that_look_numeric_stay_strings.

I couldn't run pr_ready.py fully here (Python 3.9; the repo needs 3.11+), and the harnesses need .local/.

Generated with Devin


🔄 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/2814 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/snbt-depth-and-words` --- ### 📝 Commits (2) - [`780abb9`](https://github.com/horizon-rust/horizon/commit/780abb983224d3b9911e9aedc522f6e96530bb5e) SNBT: bound nesting depth, keep nan/inf words as strings - [`b8f48f3`](https://github.com/horizon-rust/horizon/commit/b8f48f3ad0a63cc45bee319ccbb471e39c18449c) Merge remote-tracking branch 'origin/main' into upd/2814 ### 📊 Changes **2 files changed** (+208 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/component.rs` (+102 -51) 📝 `crates/horizon-world/src/nbt.rs` (+106 -50) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (Devin), not by sirrayi themselves. ## What and why Two bugs in both SNBT parsers: `horizon_world::nbt::parse_snbt` and `horizon_client::component::parse_snbt`. 1. **Unbounded recursion.** `[[[[…` nested deep enough overflowed the stack and aborted the whole process. The input can come from a command, a function file, a command block, or an old world being datafixed (`datafix/items.rs`). On a server that's a crash. Both parsers now refuse more than 512 levels (NBT's own `NbtAccounter` depth) with an error. 2. **`nan` / `inf` words.** Rust's float parse accepts `inf`, `infinity` and `nan` in any case, so bare words like `nand`, `NaNf`, `infd` and `Infinityd` became floats. In text components, `nan` and `Infinity` parsed to an f64 that serde_json turns into `null`, so `{text:nan}` lost its text. Vanilla's number grammar only takes digits. A bare word with letters other than an exponent `e`/`E` (once the type suffix is removed) is now a string. Most of the diff is re-indentation: the compound and list bodies moved into helper functions, so the depth counter goes up and down in one place. ## Vanilla reference - `NbtAccounter` (512 depth) for the limit. - `SnbtGrammar` / `TagParser` number literals: digits, sign, `.`, an exponent and a type suffix. ## Self-check - `cargo fmt --all -- --check` ✅ - `cargo clippy -p horizon-world -p horizon-client --lib --tests -- -D warnings` ✅ - `cargo test -p horizon-world --lib` (165) ✅, `cargo test -p horizon-client --lib component` ✅ - New tests: `nbt::tests::snbt_nesting_is_bounded`, `nbt::tests::snbt_bare_words_stay_strings`, `component::tests::snbt_nesting_is_bounded`, `component::tests::bare_words_that_look_numeric_stay_strings`. I couldn't run `pr_ready.py` fully here (Python 3.9; the repo needs 3.11+), and the harnesses need `.local/`. Generated with [Devin](https://devin.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:06:48 +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#4631
No description provided.