From 88a99407c07722f5d07c71dd3230875defc401f1 Mon Sep 17 00:00:00 2001 From: Sieger9303 <1517158051@qq.com> Date: Fri, 22 May 2026 12:10:41 +0800 Subject: [PATCH] fix: guard TopicPartitionList capacity --- src/topic_partition_list.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/topic_partition_list.rs b/src/topic_partition_list.rs index 4d2cfa3f4..da1afb5bb 100644 --- a/src/topic_partition_list.rs +++ b/src/topic_partition_list.rs @@ -201,7 +201,16 @@ impl TopicPartitionList { } /// Creates a new empty list with the specified capacity. + /// + /// # Panics + /// + /// Panics if `capacity` is greater than `i32::MAX`, since the underlying + /// librdkafka API accepts the capacity as a signed 32-bit integer. pub fn with_capacity(capacity: usize) -> TopicPartitionList { + assert!( + capacity <= i32::MAX as usize, + "TopicPartitionList capacity exceeds i32::MAX" + ); let ptr = unsafe { rdsys::rd_kafka_topic_partition_list_new(capacity as i32) }; unsafe { TopicPartitionList::from_ptr(ptr) } }