diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 6e184f8d3..e6d7969d2 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -227,6 +227,12 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, hb_raster_extents_t mask_ext; hb_raster_image_get_extents (mask_img, &mask_ext); const hb_raster_clip_t &old_clip = c->current_clip (); + if (unlikely (!old_clip.has_valid_alpha_mask ())) + { + hb_raster_draw_recycle_image (rdr, mask_img); + hb_raster_paint_push_empty_clip (c, w, h); + return; + } /* Convert mask extents from surface coordinates to clip-buffer coordinates. */ int mask_x0 = mask_ext.x_origin - surf->extents.x_origin; @@ -420,6 +426,11 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED, py1 = hb_min (py1, (int) h); const hb_raster_clip_t &old_clip = c->current_clip (); + if (unlikely (!old_clip.has_valid_alpha_mask ())) + { + hb_raster_paint_push_empty_clip (c, w, h); + return; + } hb_raster_clip_t new_clip = c->acquire_clip (w, h); diff --git a/src/hb-raster-paint.hh b/src/hb-raster-paint.hh index 1d6bb18a4..32c0374c1 100644 --- a/src/hb-raster-paint.hh +++ b/src/hb-raster-paint.hh @@ -79,7 +79,22 @@ struct hb_raster_clip_t return ((int) x >= rect_x0 && (int) x < rect_x1 && (int) y >= rect_y0 && (int) y < rect_y1) ? 255 : 0; if (x >= width || y >= height) return 0; - return alpha[y * stride + x]; + if (stride < width) return 0; + if (height && stride > (size_t) -1 / height) return 0; + size_t idx = (size_t) y * stride + x; + if (!alpha.arrayZ || idx >= alpha.length) return 0; + return alpha[idx]; + } + + bool has_valid_alpha_mask () const + { + if (is_rect) + return true; + if (!alpha.arrayZ || stride < width) + return false; + if (height && stride > (size_t) -1 / height) + return false; + return (size_t) stride * height <= alpha.length; } }; @@ -153,6 +168,9 @@ struct hb_raster_paint_t clip.height = h; clip.stride = (w + 3u) & ~3u; clip.is_rect = false; + clip.rect_x0 = clip.rect_y0 = 0; + clip.rect_x1 = clip.rect_y1 = 0; + clip.min_x = clip.min_y = clip.max_x = clip.max_y = 0; return clip; } diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4872362293264384 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4872362293264384 new file mode 100644 index 000000000..da19dd173 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4872362293264384 differ