diff --git a/src/hb-limits.hh b/src/hb-limits.hh index 49073d3a8..97d01128a 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh @@ -128,6 +128,14 @@ #define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30) #endif +/* Maximum surface dimension (pixels per side) when extents are derived + * from font data (glyph extents or accumulated outline bounds). Bounds + * attacker-controlled allocations; extents set explicitly through + * hb_raster_{draw,paint}_set_extents() are not limited. */ +#ifndef HB_RASTER_MAX_AUTO_DIMENSION +#define HB_RASTER_MAX_AUTO_DIMENSION 4096 +#endif + #ifndef HB_REPACKER_MAX_ITERATIONS #define HB_REPACKER_MAX_ITERATIONS 500 diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index 81401b179..763a85b85 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -346,6 +346,8 @@ hb_raster_draw_get_extents (const hb_raster_draw_t *draw, * This is equivalent to computing a transformed bounding box in pixel * space and calling hb_raster_draw_set_extents(). * + * The resulting dimensions are capped at 4096 pixels per side. + * * Return value: `true` if transformed extents are non-empty and set; * `false` otherwise. * @@ -396,8 +398,8 @@ hb_raster_draw_set_glyph_extents (hb_raster_draw_t *draw, draw->fixed_extents = { ex0, ey0, - (unsigned) ((int64_t) ex1 - ex0), - (unsigned) ((int64_t) ey1 - ey0), + (unsigned) hb_min ((int64_t) ex1 - ex0, (int64_t) HB_RASTER_MAX_AUTO_DIMENSION), + (unsigned) hb_min ((int64_t) ey1 - ey0, (int64_t) HB_RASTER_MAX_AUTO_DIMENSION), 0 }; draw->has_extents = true; @@ -1302,8 +1304,8 @@ hb_raster_draw_render (hb_raster_draw_t *draw) ext.x_origin = x0; ext.y_origin = y0; - ext.width = (unsigned) hb_max (0, x1 - x0); - ext.height = (unsigned) hb_max (0, y1 - y0); + ext.width = (unsigned) hb_min (hb_max (0, x1 - x0), HB_RASTER_MAX_AUTO_DIMENSION); + ext.height = (unsigned) hb_min (hb_max (0, y1 - y0), HB_RASTER_MAX_AUTO_DIMENSION); ext.stride = 0; /* filled below */ } } diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index edee5fd3a..360ae29a8 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -2045,6 +2045,8 @@ hb_raster_paint_get_extents (const hb_raster_paint_t *paint, * This is equivalent to computing a transformed bounding box in pixel * space and calling hb_raster_paint_set_extents(). * + * The resulting dimensions are capped at 4096 pixels per side. + * * Return value: `true` if transformed extents are non-empty and set; * `false` otherwise. * @@ -2099,8 +2101,8 @@ hb_raster_paint_set_glyph_extents (hb_raster_paint_t *paint, paint->fixed_extents = { ex0, ey0, - (unsigned) ((int64_t) ex1 - ex0), - (unsigned) ((int64_t) ey1 - ey0), + (unsigned) hb_min ((int64_t) ex1 - ex0, (int64_t) HB_RASTER_MAX_AUTO_DIMENSION), + (unsigned) hb_min ((int64_t) ey1 - ey0, (int64_t) HB_RASTER_MAX_AUTO_DIMENSION), 0 }; paint->has_extents = true; diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6344015149858816 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6344015149858816 new file mode 100644 index 000000000..85daa6cff Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-6344015149858816 differ