[PR #7751] Default oversized item NBT counts to one #7799

Open
opened 2026-11-03 07:24:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7751
Author: @TheMrZZ
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/nbt-item-count-range


📝 Commits (1)

  • e757345 Default invalid item NBT counts to one

📊 Changes

2 files changed (+81 additions, -2 deletions)

View changed files

📝 crates/horizon-items/src/item_nbt.rs (+49 -2)
📝 tools/command_exec_corpus.py (+32 -0)

📄 Description

🤖 Opened by TheMrZZ's AI agent (Codex, gpt-6.1-sol), not by TheMrZZ personally.

What and why

Fixes #7724. Loading an item stack from NBT now defaults an out-of-range count to 1. Counts 100, 255, 256 and 2147483647 previously survived decoding. Count 99 stays valid even for a diamond sword, independently of its normal stack limit. The range check applies in the NBT decoder; runtime stack counts retain their existing behavior.

Kind

  • parity: Horizon now does what vanilla 26.3 does

Vanilla reference

Official 26.3 ItemStack's codec construction (lambda$static$1) uses ExtraCodecs.intRange(1,99) with ExtraCodecs.optionalAlwaysPresentFieldOf("count",1).

The new item NBT count bounds command-execution corpus compares armor-stand equipment and chest inventory NBT for stone and diamond swords. It covers missing count, -1, 0, 1, 2, 64, 99, 100, 255, 256, 2147483647, byte 1, float 1.5 and string "1". Fresh Java 26.3 versus the baseline matches 154/170 observations, with exactly 16 oversized-count differences; the fixed binary matches 170/170. Both runs use identical scripts and byte-identical Java reference records. The observations read normalized NBT directly.

The decoder unit fails on the old source (100 instead of 1) and passes with the fix. A separate unit retains runtime construction and encoding of count 1000. This change targets the count bounds within the existing decoder, without introducing broader numeric or component validation.

Other projects' code

None.

Self-check

pr_ready (tools/pr_ready.py --quick on a local runner, against origin/main at 6ed5b17a6, 4 min 43 s)

Check Result
Scope ✅ 2 files, +81 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 2 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 40 s)
tests: horizon-items ✅ 57 passed (2 s)
doc tests ✅ 0 passed (2 s)
content root tests ✅ 24 passed (1 min 49 s)
mod API up to date ➖ native hooks 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)

🤖 Generated with Codex.


🔄 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/7751 **Author:** [@TheMrZZ](https://github.com/TheMrZZ) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/nbt-item-count-range` --- ### 📝 Commits (1) - [`e757345`](https://github.com/horizon-rust/horizon/commit/e7573451d7b2e0774d0e9b5408fb1595b07cc020) Default invalid item NBT counts to one ### 📊 Changes **2 files changed** (+81 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-items/src/item_nbt.rs` (+49 -2) 📝 `tools/command_exec_corpus.py` (+32 -0) </details> ### 📄 Description > 🤖 Opened by TheMrZZ's AI agent (Codex, gpt-6.1-sol), not by TheMrZZ personally. ## What and why Fixes #7724. Loading an item stack from NBT now defaults an out-of-range count to 1. Counts 100, 255, 256 and 2147483647 previously survived decoding. Count 99 stays valid even for a diamond sword, independently of its normal stack limit. The range check applies in the NBT decoder; runtime stack counts retain their existing behavior. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does ## Vanilla reference Official 26.3 `ItemStack`'s codec construction (`lambda$static$1`) uses `ExtraCodecs.intRange(1,99)` with `ExtraCodecs.optionalAlwaysPresentFieldOf("count",1)`. The new `item NBT count bounds` command-execution corpus compares armor-stand equipment and chest inventory NBT for stone and diamond swords. It covers missing count, -1, 0, 1, 2, 64, 99, 100, 255, 256, 2147483647, byte 1, float 1.5 and string "1". Fresh Java 26.3 versus the baseline matches 154/170 observations, with exactly 16 oversized-count differences; the fixed binary matches 170/170. Both runs use identical scripts and byte-identical Java reference records. The observations read normalized NBT directly. The decoder unit fails on the old source (`100` instead of `1`) and passes with the fix. A separate unit retains runtime construction and encoding of count 1000. This change targets the count bounds within the existing decoder, without introducing broader numeric or component validation. ## Other projects' code None. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on a local runner, against origin/main at 6ed5b17a6, 4 min 43 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +81 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 2 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 40 s) | | tests: horizon-items | ✅ 57 passed (2 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ✅ 24 passed (1 min 49 s) | | mod API up to date | ➖ native hooks 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) | 🤖 Generated with [Codex](https://openai.com/codex/). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7799
No description provided.