This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 870fb06f73 test: add overflow tests for MutableBuffer (#9958)
870fb06f73 is described below

commit 870fb06f73c45d9d09565d7b83cd83139a74424f
Author: Soiman Vasile <[email protected]>
AuthorDate: Tue Jun 2 18:36:07 2026 +0300

    test: add overflow tests for MutableBuffer (#9958)
    
    ### Description
    While analyzing the memory allocation logic in `MutableBuffer`, I
    identified that the `with_capacity` and `reserve` methods correctly use
    `.expect()` guards to prevent integer overflows.
    
    However, I couldnt find test cases for this `.expect()` guard in the
    current test suite. This PR adds 2 `#[should_panic]` tests in
    `mutable.rs` to verify that the API correctly panics
    **Changes:**
    * Added `test_mutable_new_capacity_overflow` to cover
    `MutableBuffer::new`
    * Added `test_mutable_reserve_overflow` to cover
    `MutableBuffer::reserve`
    
    ###  Rationale
    Adding these tests ensures that the safety guards in `arrow-buffer`
    remain intact and provides explicit coverage for edge cases involving
    near-`usize::MAX` allocations.
    
    ### Tests
    -  `test_mutable_new_capacity_overflow`
    - `test_mutable_reserve_overflow`
    
    Co-authored-by: Andrew Lamb <[email protected]>
---
 arrow-buffer/src/buffer/mutable.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arrow-buffer/src/buffer/mutable.rs 
b/arrow-buffer/src/buffer/mutable.rs
index aff1f138c2..b6e6a70c6c 100644
--- a/arrow-buffer/src/buffer/mutable.rs
+++ b/arrow-buffer/src/buffer/mutable.rs
@@ -1669,4 +1669,20 @@ mod tests {
         let data_1000: Vec<i32> = (0..1000).collect();
         test_repeat_count(repeat_count, &data_1000);
     }
+
+    #[test]
+    #[should_panic(expected = "failed to round upto multiple of 64")]
+    fn test_mutable_new_capacity_overflow() {
+        // Tests overflow during initial allocation
+        let _ = MutableBuffer::new(usize::MAX - 10);
+    }
+
+    #[test]
+    #[should_panic(expected = "buffer length overflow")]
+    fn test_mutable_reserve_overflow() {
+        // Tests overflow during growth (checked_add)
+        let mut buf = MutableBuffer::new(1);
+        buf.push(1u8);
+        buf.reserve(usize::MAX);
+    }
 }

Reply via email to