[raster] Validate non-rect clip masks before reuse

The raster paint clip code indexed non-rect clip alpha rows directly,
assuming the clip metadata always matched a full stride*height backing
buffer. Fuzzing showed that reused clip objects can reach those reads
with stale scalar state, which turns the row access in
push_clip_rectangle() into a heap-buffer-overflow.

Reset cached clip geometry on acquire, add a validity check for
non-rect alpha masks, and refuse to build new clip intersections from
an invalid mask. The fallback is an empty clip, which keeps the paint
path safe without affecting well-formed clips.

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Behdad EsfahbodandOpenAI Codex committed 2026-04-03 17:17:49 -06:00
1 parent 9f64e3fde2
commit 19e4bf2597
3 files changed
+30 -1

No files matched your search

+11
View File
@@ -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);
+19 -1
View File
@@ -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;
}