From 11153bb423e4415b212569b1f5a189e93c31b6a8 Mon Sep 17 00:00:00 2001 From: stringhandler Date: Wed, 17 Jun 2026 09:11:39 +0200 Subject: [PATCH] fix: prevent silent overflow in calloc --- simplicity-sys/src/alloc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplicity-sys/src/alloc.rs b/simplicity-sys/src/alloc.rs index 0f963500..e875088d 100644 --- a/simplicity-sys/src/alloc.rs +++ b/simplicity-sys/src/alloc.rs @@ -87,7 +87,7 @@ pub unsafe extern "C" fn rust_0_7_malloc(size_bytes: usize) -> *mut u8 { /// Allocated bytes must be freed using [`rust_0_7_free`]. #[no_mangle] pub unsafe extern "C" fn rust_0_7_calloc(num: usize, size: usize) -> *mut u8 { - let size_bytes = num * size; + let size_bytes = num.saturating_mul(size); // SAFETY: Allocator is `alloc_alloc_zeroed`. allocate(size_bytes, alloc::alloc_zeroed) }