From adcfdceb8644a2fcbff92edc0eb81dbdf9e47409 Mon Sep 17 00:00:00 2001 From: hemanth94 Date: Sat, 15 Feb 2025 14:30:05 +0530 Subject: [PATCH] fix: Checking overflow in Sliced function (#21207) --- crates/polars-arrow/src/array/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/polars-arrow/src/array/mod.rs b/crates/polars-arrow/src/array/mod.rs index 45189274d057..76d68d0a1b5a 100644 --- a/crates/polars-arrow/src/array/mod.rs +++ b/crates/polars-arrow/src/array/mod.rs @@ -444,8 +444,11 @@ macro_rules! impl_sliced { #[inline] #[must_use] pub fn sliced(self, offset: usize, length: usize) -> Self { + let total = offset + .checked_add(length) + .expect("offset + length overflowed"); assert!( - offset + length <= self.len(), + total <= self.len(), "the offset of the new Buffer cannot exceed the existing length" ); unsafe { Self::sliced_unchecked(self, offset, length) }