[GH-ISSUE #3884] Data-pack recipe result counts are not validated: 0 / 2^31 / 2^32 wrap into result stacks #1127

Closed
opened 2026-11-02 15:44:28 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @ccclosed on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3884

🤖 Filed by ccclosed's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by ccclosed personally.

Severity: Medium — content pack can mint invalid/2-billion stacks; debug panic
Snapshot: origin/main 7c1e0f979 (2026-10-30)

What happens

A data pack's recipe result.count is parsed with as u64 and cast to u32 with no validation, in several loaders:

  • crafting recipes: crates/horizon-client/src/crafting.rs:104 — count: v["count"].as_u64().unwrap_or(1) as u32
  • stonecutting/cooking materialisation: crates/horizon-client/src/stations.rs (result stacks built from the parsed count)
  • the brewing loader: crates/horizon-client/src/brewing.rs (output.count copied verbatim — this one was also observed independently)

0 stays 0 (a count-0 Some stack, which the menu/handler code assumes cannot exist), 2^31 is accepted, 2^32 wraps to 0, u32::MAX is accepted. A single crafted log/stonecutting/cooking recipe then yields a stack with billions of items, and furnace/brewing ticks do count -= 1 / count += n on it unguarded.

Vanilla bounds this at load with ItemStackTemplate.CODEC's ExtraCodecs.intRange(1, 99) (verified with javap -p -c on the shipped 26.3 client jar by the audit), so a bad pack value never reaches a stack.

Repro

  • Data pack with {"type":"minecraft:crafting_shapeless","ingredients":[{"item":"minecraft:stone"}],"result":{"id":"minecraft:netherite_ingot","count":4294967295}}: craft once → 4 294 967 295 netherite ingots.
  • count: 0 → result slot with a count-0 stack (eats the ingredient).
  • count: 4294967296 → wraps to 0.

Suggested fix

Validate the parse (reject outside 1..=99 as vanilla does) in the recipe/brewing loaders before the as u32 cast; also reject count 0 wherever an Option<ItemStack> is built from untrusted data. (This is the same family as the audit's count-0 dupe finding — I can provide the minimal tests.)

Originally created by @ccclosed on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3884 > 🤖 Filed by ccclosed's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by ccclosed personally. **Severity:** Medium — content pack can mint invalid/2-billion stacks; debug panic **Snapshot:** `origin/main` `7c1e0f979` (2026-10-30) ### What happens A data pack's recipe `result.count` is parsed with `as u64` and cast to `u32` with no validation, in several loaders: - crafting recipes: `crates/horizon-client/src/crafting.rs:104` — `count: v["count"].as_u64().unwrap_or(1) as u32` - stonecutting/cooking materialisation: `crates/horizon-client/src/stations.rs` (result stacks built from the parsed count) - the brewing loader: `crates/horizon-client/src/brewing.rs` (`output.count` copied verbatim — this one was also observed independently) `0` stays `0` (a count-0 `Some` stack, which the menu/handler code assumes cannot exist), `2^31` is accepted, `2^32` wraps to `0`, `u32::MAX` is accepted. A single crafted log/stonecutting/cooking recipe then yields a stack with billions of items, and furnace/brewing ticks do `count -= 1` / `count += n` on it unguarded. Vanilla bounds this **at load** with `ItemStackTemplate.CODEC`'s `ExtraCodecs.intRange(1, 99)` (verified with `javap -p -c` on the shipped 26.3 client jar by the audit), so a bad pack value never reaches a stack. ### Repro - Data pack with `{"type":"minecraft:crafting_shapeless","ingredients":[{"item":"minecraft:stone"}],"result":{"id":"minecraft:netherite_ingot","count":4294967295}}`: craft once → 4 294 967 295 netherite ingots. - `count: 0` → result slot with a count-0 stack (eats the ingredient). - `count: 4294967296` → wraps to 0. ### Suggested fix Validate the parse (reject outside `1..=99` as vanilla does) in the recipe/brewing loaders before the `as u32` cast; also reject count 0 wherever an `Option<ItemStack>` is built from untrusted data. (This is the same family as the audit's count-0 dupe finding — I can provide the minimal tests.)
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#1127
No description provided.