From 844f3eeb714600d452a09f3e31477741b3f5bef4 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Thu, 18 Sep 2025 13:16:36 -0400 Subject: [PATCH] Fix chunks peek_with_bitmaps panic (#38430) This panic only happened in debug builds because of a left shift overflow. The slice range has bounds between 0 and 128. The 128 case caused the overflow. We now do an unbounded shift and a wrapped sub to get the correct bitmask. If the slice range is 128 left, it should make 1 zero. Then the wrapped sub would flip all bits, which is expected behavior. Release Notes: - N/A Co-authored-by: Nia --- crates/rope/src/rope.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index 8bcaef20ca3bd5c79413791764a313fd1e6b75ac..41dd585742ec35b409777f64658800d257b11b86 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -784,7 +784,10 @@ impl<'a> Chunks<'a> { slice_start..slice_end }; - let bitmask = (1u128 << slice_range.end as u128).saturating_sub(1); + // slice range has a bounds between 0 and 128 in non test builds + // We use a non wrapping sub because we want to overflow in the case where slice_range.end == 128 + // because that represents a full chunk and the bitmask shouldn't remove anything + let bitmask = (1u128.unbounded_shl(slice_range.end as u32)).wrapping_sub(1); let chars = (chunk.chars() & bitmask) >> slice_range.start; let tabs = (chunk.tabs & bitmask) >> slice_range.start;