From adbc8e2b6a3d15028770fd3cccb3b2dda776feed Mon Sep 17 00:00:00 2001 From: BitForge <150640405+CompileRider@users.noreply.github.com> Date: Tue, 7 Jul 2026 09:53:11 -0400 Subject: [PATCH] fix: prevent capacity overflow crash (#2348) * fix: prevent capacity overflow crash when flying with elytra or in creative mode The NoiseBasedCountPlacementModifier::get_count() can return negative i32 values when foliage noise sampling produces negative results at certain world coordinates. The previous code cast this negative i32 directly to usize, causing an integer wrap to ~18 quintillion, which triggered a capacity overflow panic in Vec allocation during chunk feature generation. This aligns with vanilla Minecraft behavior which also clamps the count to a minimum of 0 before using it. Closes #2345 * Hi --- pumpkin-world/src/generation/feature/placed_features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpkin-world/src/generation/feature/placed_features.rs b/pumpkin-world/src/generation/feature/placed_features.rs index 1e1a74801..5ee61c4f1 100644 --- a/pumpkin-world/src/generation/feature/placed_features.rs +++ b/pumpkin-world/src/generation/feature/placed_features.rs @@ -516,7 +516,7 @@ pub trait CountPlacementModifierBase { random: &mut RandomGenerator, pos: BlockPos, ) -> Box> { - let count = self.get_count(random, pos); + let count = self.get_count(random, pos).max(0); // Vanilla treats negative counts as 0, but `i32 as usize` in Rust would wrap. Box::new(std::iter::repeat_n(pos, count as usize)) }