Skip to content

Commit cbc15b8

Browse files
Renyi Zhaosdroege
authored andcommitted
cairo: Fix integer overflow in create_for_data's len check
1 parent b1bc851 commit cbc15b8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cairo/src/image_surface.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ impl ImageSurface {
6464
(data.as_mut_ptr(), data.len())
6565
};
6666

67-
assert!(len >= (height * stride) as usize);
67+
assert!(width >= 0, "width must be non-negative");
68+
assert!(height >= 0, "height must be non-negative");
69+
assert!(stride >= 0, "stride must be non-negative");
70+
71+
// check if there is integer overflow
72+
assert!(len >= height.checked_mul(stride).unwrap() as usize);
6873
let result = unsafe {
6974
ImageSurface::from_raw_full(ffi::cairo_image_surface_create_for_data(
7075
ptr,

0 commit comments

Comments
 (0)