summaryrefslogtreecommitdiff
path: root/src/cairo-image-surface.c
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2021-05-05 13:43:57 +0000
committerJonathan Kew <jfkthame@googlemail.com>2021-05-05 13:43:57 +0000
commitac23567a0cf5562bd7547030cd849d8d302da919 (patch)
tree7cb708ca14833737d54e8f0cf5d26263303211f9 /src/cairo-image-surface.c
parent3894a1ab3322ce6c71c626daca814b4a7ac0d299 (diff)
downloadcairo-ac23567a0cf5562bd7547030cd849d8d302da919.tar.gz
Bail early from _cairo_image_compute_color if image is zero-sized.
This avoids the risk of encountering undefined behavior when computing the `pixel` pointer (even though it won't actually be used) in the case where the image width or height is zero and the data is NULL. (Observed when called from cairo_pdf_surface code when an extreme scaling transform was present, though I guess there are probably other ways to end up with such an image.)
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r--src/cairo-image-surface.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 0e17f3a16..3b11eb981 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1243,6 +1243,9 @@ _cairo_image_compute_color (cairo_image_surface_t *image)
int x, y;
cairo_image_color_t color;
+ if (image->width == 0 || image->height == 0)
+ return CAIRO_IMAGE_IS_MONOCHROME;
+
if (image->format == CAIRO_FORMAT_A1)
return CAIRO_IMAGE_IS_MONOCHROME;