mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 14:01:10 +01:00
* [raster] Bound embedded PNG dimensions before decoding hb_raster_paint_image() handed a font's embedded sbix/CBDT PNG to deserialize_from_png(), which allocated and filled the whole image at whatever size the PNG's IHDR declared (up to two buffers at the 1 GiB HB_RASTER_MAX_BUFFER_SIZE cap each), and only charged src_width * src_height against the pixel budget after the decode had finished. A 33 KB sbix font with a blank 16384x16384 1-bit PNG therefore made the raster backend allocate and touch ~2 GiB of memory per painted glyph, independent of the requested output size. Surfaces whose size comes from font data are already clamped to HB_RASTER_MAX_AUTO_DIMENSION (4096 per side); the PNG decoder was not. deserialize_from_png() gains a max_dimension parameter checked right after png_get_IHDR(), before any allocation, and the paint callback passes HB_RASTER_MAX_AUTO_DIMENSION. The public hb_raster_image_deserialize_from_png_or_fail() keeps its INT_MAX behaviour through the default argument, matching the limit's documented intent that explicitly requested sizes are not bounded. With the cap a decode is at most 16M pixels, whose cost fits the 2^26 pixel budget, so the later charge_work() is adequate. Behaviour change: sbix/CBDT PNG glyphs wider or taller than 4096 pixels are no longer painted by the raster backend (the callback returns false, as for any undecodable image). The cairo backend has the same weakness on a different code path and was already fixed separately (#6497). test_image_png_size() in test/api/test-raster.cc paints a 4096- and a 4097-pixel-wide PNG and checks that only the former lands; it fails on the unpatched library. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ENME4ECM. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [raster] Charge the scanline sweep to the pixel budget hb_raster_draw_render() walks every active edge once per pixel row it spans, a product (edges times rows) that neither HB_RASTER_MAX_DRAW_EDGES (2^20) nor HB_RASTER_MAX_AUTO_DIMENSION (4096 rows) bounds, and that nothing charged: the outline budget only sees traversal and curve flattening. A 10 KB glyf font of 199,800 full-height straight edges therefore cost tens of seconds of CPU for a single render. PR #6244 added the precharge for the paint path but sized it by the paint *surface*, which comes from the font's declared glyph extents, while the mask rasterizer auto-sizes the mask from the outline itself; a 1x1 ClipBox or empty bounding box slipped the full-height sweep past it. The direct draw path had no check at all. This charges the sweep inside hb_raster_draw_render(), where the extents really rendered are known, estimating it with the existing hb_raster_draw_get_pixel_work() helper, now clamped to those extents (the fixed ones, else the 4096 auto cap) rather than taking them as arguments. The sweep is skipped when the estimate exceeds the per-session pixel allowance raster-paint already uses, max(HB_BUDGET_RASTER_PIXELS, HB_BUDGET_RASTER_PAINT_PASSES * width * height). The two paint callers now use the mask-relative estimate, and hb_raster_paint_attach_clip_rdr() seeds HB_BUDGET_UNLIMITED into the mask rasterizer when the paint policy is unlimited, so opting out of limits still disables the check. hb_raster_draw_get_pixel_work() is HB_INTERNAL, so dropping its two arguments changes no public API/ABI. Behaviour change: an over-budget render returns a blank image of the computed size (documented in the API comment) rather than NULL. Letting HB_BUDGET_UNLIMITED switch the check off matches the paint pixel budget's semantics and keeps the edge and dimension caps active; whether this bound should instead be an unconditional structural cap is a maintainer's choice. Testing: the finding's reproducer flips from BUG to OK, its attack render dropping from ~39 s to 0.05 s of CPU while the control is unchanged; the api suite passes under both the optimized and the ASan/UBSan build. test_budget_sweep in test/api/test-raster.cc covers the direct draw path with auto and fixed extents and the small-surface paint-clip path. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8PTXE0MD. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>