diff --git a/NEWS b/NEWS index 550701f3c..5137a5f32 100644 --- a/NEWS +++ b/NEWS @@ -2,14 +2,16 @@ Overview of changes leading to NEXT (REPLACEME) ===================================== - GPU library: - * New color-glyph paint renderer. hb_gpu_paint_t walks a font's - paint tree (COLRv0 or COLRv1) and encodes its layers -- solid - fills, linear / radial / sweep gradients, transforms, composite - groups -- into a compact blob. A new fragment-shader function - hb_gpu_paint() renders the blob in premultiplied RGBA; - monochrome glyphs are handled transparently via a synthesized - foreground-colored layer. Shader sources provided in GLSL, - WGSL, MSL, and HLSL. + + * New color-glyph paint renderer, based on design by LĂȘ Duy Quang. + hb_gpu_paint_t walks a font's paint tree (COLRv0 or COLRv1) and + encodes its layers -- solid fills, linear / radial / sweep + gradients, transforms, composite groups -- into a compact blob. + A new fragment-shader function hb_gpu_paint() renders the blob + in premultiplied RGBA; monochrome glyphs are handled + transparently via a synthesized foreground-colored layer. + Shader sources provided in GLSL, WGSL, MSL, and HLSL. + * Paint encoder limitations: the encoder sets `unsupported` and returns NULL when `num_ops` would exceed 32767, `push_group` nests deeper than 4, or the paint tree calls back through the diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index 37fac8909..4f89f1011 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -108,7 +108,7 @@ inline bool will_overflow (graph_t& graph, hb_vector_t* overflows = nullptr) { - if (overflows) overflows->resize (0); + if (overflows) overflows->clear (); graph.update_positions (); hb_hashmap_t record_set; diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 05725048c..7525e5a57 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -117,9 +117,15 @@ struct hb_bit_set_t void clear () { - resize (0); - if (likely (successful)) - population = 0; + /* Early-out on already-empty. Protects the Null singleton + * (which is zero-initialized) from any writes. Any non-empty + * instance is a real heap object with writable storage, so + * clearing through the vector's always-safe clear() is fine + * even if we entered error state. */ + if (!pages.length && !population) return; + pages.clear (); + page_map.clear (); + population = 0; } bool is_empty () const { diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index c210230dd..03a29832d 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -52,6 +52,12 @@ acc_emit (hb_gpu_draw_t *g, double p2x, double p2y, double p3x, double p3y) { + if (unlikely (g->num_curves >= HB_GPU_DRAW_MAX_CURVES)) + { + g->success = false; + return; + } + hb_gpu_curve_t c = {p1x, p1y, p2x, p2y, p3x, p3y, contour_start}; if (unlikely (!g->curves.push_or_fail (c))) { diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 8aa3f1529..ff8bc94aa 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -1441,15 +1441,20 @@ hb_gpu_paint_encode (hb_gpu_paint_t *paint, void hb_gpu_paint_clear (hb_gpu_paint_t *paint) { - paint->ops.resize (0); + /* Use reset() not resize(0): if an earlier push_or_fail() set + * the vector's error state (common under failing-malloc), + * resize(0) short-circuits without clearing length. A + * subsequent clear would double-destroy the blob pointers left + * in the array, or keep stale ops across encodes. */ + paint->ops.reset (); paint->num_ops = 0; for (hb_blob_t *b : paint->sub_blobs) hb_blob_destroy (b); - paint->sub_blobs.resize (0); + paint->sub_blobs.reset (); paint->clip_depth = 0; paint->unsupported = false; paint->cur_transform = {1, 0, 0, 1, 0, 0}; - paint->transform_stack.resize (0); + paint->transform_stack.reset (); paint->ext_min_x = 0x7fffffff; paint->ext_min_y = 0x7fffffff; paint->ext_max_x = -0x7fffffff; diff --git a/src/hb-limits.hh b/src/hb-limits.hh index f5f6073e9..9d6c7ec68 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh @@ -112,6 +112,10 @@ #define HB_SVG_MAX_PATH_SEGMENTS 262144 #endif +#ifndef HB_GPU_DRAW_MAX_CURVES +#define HB_GPU_DRAW_MAX_CURVES 65536 +#endif + #ifndef HB_SVG_MAX_DOCUMENT_SIZE #define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20) #endif diff --git a/src/hb-map.hh b/src/hb-map.hh index fefdbb19d..37cc2460b 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -379,7 +379,11 @@ struct hb_hashmap_t void clear () { - if (unlikely (!successful)) return; + /* Early-out on already-empty. Protects the Null singleton + * (zero-initialized) from any writes. Any non-empty hashmap + * is a real heap instance with writable items, so clearing + * under !successful is safe. */ + if (!population && !occupancy) return; for (auto &_ : hb_iter (items, size ())) { diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 805b14d73..bddb5e69e 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -731,7 +731,8 @@ hb_pdf_build_gradient_function (hb_pdf_resources_t *res, hb_color_line_t *color_line) { unsigned count = hb_color_line_get_color_stops (color_line, 0, nullptr, nullptr); - paint->color_stops_scratch.resize (count); + if (unlikely (!paint->color_stops_scratch.resize (count))) + return 0; hb_color_line_get_color_stops (color_line, 0, &count, paint->color_stops_scratch.arrayZ); if (count < 2) @@ -1042,7 +1043,8 @@ hb_pdf_paint_sweep_gradient (hb_paint_funcs_t *, /* Get and sort color stops. */ unsigned n_stops = hb_color_line_get_color_stops (color_line, 0, nullptr, nullptr); - paint->color_stops_scratch.resize (n_stops); + if (unlikely (!paint->color_stops_scratch.resize (n_stops))) + return; hb_color_line_get_color_stops (color_line, 0, &n_stops, paint->color_stops_scratch.arrayZ); paint->color_stops_scratch.as_array ().qsort ( [] (const hb_color_stop_t &a, const hb_color_stop_t &b) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 600d78c13..e831c72b4 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -182,7 +182,7 @@ struct hb_vector_t { if (unlikely (in_error ())) reset_error (); - resize (0); + clear (); return *this; } diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-7148eb19cc1a927d3bb5773630d4d9829fae5fbc b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-7148eb19cc1a927d3bb5773630d4d9829fae5fbc new file mode 100644 index 000000000..e4c214bc6 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-gpu-fuzzer-7148eb19cc1a927d3bb5773630d4d9829fae5fbc differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-5620949889384448 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-5620949889384448 new file mode 100644 index 000000000..bcfb825c5 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-5620949889384448 differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-6727871677923328 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-6727871677923328 new file mode 100644 index 000000000..0b48f8e90 Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-vector-fuzzer-6727871677923328 differ