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
This commit is contained in:
BitForge
2026-07-07 09:53:11 -04:00
committed by GitHub
parent 0de72cbf18
commit adbc8e2b6a

View File

@@ -516,7 +516,7 @@ pub trait CountPlacementModifierBase {
random: &mut RandomGenerator,
pos: BlockPos,
) -> Box<dyn Iterator<Item = BlockPos>> {
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))
}