Skip to content

Commit b1bc851

Browse files
Renyi Zhaosdroege
authored andcommitted
cairo: Add bounds check for nth in region_get_rectangle to prevent UB
1 parent 2eb2f7e commit b1bc851

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

cairo/src/region.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ impl Region {
176176
#[doc(alias = "get_rectangle")]
177177
#[doc(alias = "cairo_region_get_rectangle")]
178178
pub fn rectangle(&self, nth: i32) -> RectangleInt {
179+
let total_rectangles = self.num_rectangles();
180+
assert!(nth >= 0 && nth < total_rectangles, "nth is out of range");
179181
unsafe {
180182
let rectangle: RectangleInt = ::std::mem::zeroed();
181183
ffi::cairo_region_get_rectangle(self.0.as_ptr(), nth, rectangle.to_raw_none());

0 commit comments

Comments
 (0)