mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[raster] Cap font-derived surface dimensions at 4096 pixels per side
When no extents are set explicitly, the paint and draw contexts
derive the surface size from font data: glyph extents (which the
auto path in hb_raster_paint_glyph_impl () feeds through
set_glyph_extents ()) or the accumulated outline bounds in
hb_raster_draw_render (). A malicious font with a tiny upem and
huge glyph coordinates turns that into arbitrarily large
allocations: a 49 KB fuzz font produced several ~885 MB BGRA
surfaces live at once (root surface plus one per PaintComposite
push_group), nearly 4 GB total.
Add HB_RASTER_MAX_AUTO_DIMENSION (4096) to hb-limits.hh and clamp
width/height at the three font-derived sizing points: both
set_glyph_extents () implementations and draw render's
auto-size-from-edges path. Since push_group and clip surfaces
inherit fixed_extents, the cap bounds those too. Extents set
explicitly via hb_raster_{draw,paint}_set_extents () are not
limited.
Fixes an hb-raster-fuzzer out-of-memory finding (testcase
6344015149858816): peak RSS 3.47 GB before, 350 MB after.
Testcase added as a fuzz seed. Full meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c2b6b09ed2
commit
bbfe29975d
4 files changed
+18
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user