From 32d8dc6fb9eb9c41e79e3fe0b1cb57fc3f0040b6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 11 Jun 2026 10:14:23 +0200 Subject: [PATCH 1/3] [COLR] Sanitize composite mode before paint callbacks COLR PaintComposite stores its composite mode as an untrusted table byte, while the paint callbacks take hb_paint_composite_mode_t. Avoid casting unsupported table values directly to the public enum. Map unrecognized values to CLEAR, as required by the COLR table comment, before calling push_group_for() and pop_group(). Also drop the duplicated COLR-side composite mode enum values and use the public paint enum names for the accepted values. Testing: meson test -C build Assisted-by: OpenAI Codex --- src/OT/Color/COLR/COLR.hh | 80 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 4b8afb407..dd1dbd15d 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -561,44 +561,6 @@ struct ColorLine // or all of the specified modes. struct CompositeMode : HBUINT8 { - enum { - // Porter-Duff modes - // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators - COMPOSITE_CLEAR = 0, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_clear - COMPOSITE_SRC = 1, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_src - COMPOSITE_DEST = 2, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dst - COMPOSITE_SRC_OVER = 3, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcover - COMPOSITE_DEST_OVER = 4, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstover - COMPOSITE_SRC_IN = 5, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcin - COMPOSITE_DEST_IN = 6, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstin - COMPOSITE_SRC_OUT = 7, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcout - COMPOSITE_DEST_OUT = 8, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstout - COMPOSITE_SRC_ATOP = 9, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcatop - COMPOSITE_DEST_ATOP = 10, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstatop - COMPOSITE_XOR = 11, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_xor - COMPOSITE_PLUS = 12, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_plus - - // Blend modes - // https://www.w3.org/TR/compositing-1/#blending - COMPOSITE_SCREEN = 13, // https://www.w3.org/TR/compositing-1/#blendingscreen - COMPOSITE_OVERLAY = 14, // https://www.w3.org/TR/compositing-1/#blendingoverlay - COMPOSITE_DARKEN = 15, // https://www.w3.org/TR/compositing-1/#blendingdarken - COMPOSITE_LIGHTEN = 16, // https://www.w3.org/TR/compositing-1/#blendinglighten - COMPOSITE_COLOR_DODGE = 17, // https://www.w3.org/TR/compositing-1/#blendingcolordodge - COMPOSITE_COLOR_BURN = 18, // https://www.w3.org/TR/compositing-1/#blendingcolorburn - COMPOSITE_HARD_LIGHT = 19, // https://www.w3.org/TR/compositing-1/#blendinghardlight - COMPOSITE_SOFT_LIGHT = 20, // https://www.w3.org/TR/compositing-1/#blendingsoftlight - COMPOSITE_DIFFERENCE = 21, // https://www.w3.org/TR/compositing-1/#blendingdifference - COMPOSITE_EXCLUSION = 22, // https://www.w3.org/TR/compositing-1/#blendingexclusion - COMPOSITE_MULTIPLY = 23, // https://www.w3.org/TR/compositing-1/#blendingmultiply - - // Modes that, uniquely, do not operate on components - // https://www.w3.org/TR/compositing-1/#blendingnonseparable - COMPOSITE_HSL_HUE = 24, // https://www.w3.org/TR/compositing-1/#blendinghue - COMPOSITE_HSL_SATURATION = 25, // https://www.w3.org/TR/compositing-1/#blendingsaturation - COMPOSITE_HSL_COLOR = 26, // https://www.w3.org/TR/compositing-1/#blendingcolor - COMPOSITE_HSL_LUMINOSITY = 27, // https://www.w3.org/TR/compositing-1/#blendingluminosity - }; public: DEFINE_SIZE_STATIC (1); }; @@ -1532,11 +1494,49 @@ struct PaintComposite void paint_glyph (hb_paint_context_t *c) const { TRACE_PAINT (this); + hb_paint_composite_mode_t composite_mode; + switch ((unsigned int) mode) + { + case HB_PAINT_COMPOSITE_MODE_CLEAR: + case HB_PAINT_COMPOSITE_MODE_SRC: + case HB_PAINT_COMPOSITE_MODE_DEST: + case HB_PAINT_COMPOSITE_MODE_SRC_OVER: + case HB_PAINT_COMPOSITE_MODE_DEST_OVER: + case HB_PAINT_COMPOSITE_MODE_SRC_IN: + case HB_PAINT_COMPOSITE_MODE_DEST_IN: + case HB_PAINT_COMPOSITE_MODE_SRC_OUT: + case HB_PAINT_COMPOSITE_MODE_DEST_OUT: + case HB_PAINT_COMPOSITE_MODE_SRC_ATOP: + case HB_PAINT_COMPOSITE_MODE_DEST_ATOP: + case HB_PAINT_COMPOSITE_MODE_XOR: + case HB_PAINT_COMPOSITE_MODE_PLUS: + case HB_PAINT_COMPOSITE_MODE_SCREEN: + case HB_PAINT_COMPOSITE_MODE_OVERLAY: + case HB_PAINT_COMPOSITE_MODE_DARKEN: + case HB_PAINT_COMPOSITE_MODE_LIGHTEN: + case HB_PAINT_COMPOSITE_MODE_COLOR_DODGE: + case HB_PAINT_COMPOSITE_MODE_COLOR_BURN: + case HB_PAINT_COMPOSITE_MODE_HARD_LIGHT: + case HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT: + case HB_PAINT_COMPOSITE_MODE_DIFFERENCE: + case HB_PAINT_COMPOSITE_MODE_EXCLUSION: + case HB_PAINT_COMPOSITE_MODE_MULTIPLY: + case HB_PAINT_COMPOSITE_MODE_HSL_HUE: + case HB_PAINT_COMPOSITE_MODE_HSL_SATURATION: + case HB_PAINT_COMPOSITE_MODE_HSL_COLOR: + case HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY: + composite_mode = (hb_paint_composite_mode_t) (unsigned int) mode; + break; + default: + composite_mode = HB_PAINT_COMPOSITE_MODE_CLEAR; + break; + } + c->funcs->push_group_for (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); c->recurse (this+backdrop); - c->funcs->push_group_for (c->data, (hb_paint_composite_mode_t) (int) mode); + c->funcs->push_group_for (c->data, composite_mode); c->recurse (this+src); - c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode); + c->funcs->pop_group (c->data, composite_mode); c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); } From fa417b9a77735a28195eb81848dfbc0d4058708f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 11 Jun 2026 10:22:09 +0200 Subject: [PATCH 2/3] [CFF] Check numeric conversion to int Malformed CFF dictionaries can contain real operands outside the representable range of int. Avoid converting those values directly in number_t::to_int(), and make arg_stack_t::pop_int() set the interpreter error when the checked conversion fails. Also make in_int_range() test the stored double value before converting, so serialization-side range checks do not depend on an unchecked conversion. Testing: meson test -C build Assisted-by: OpenAI Codex --- src/hb-cff-interp-common.hh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index df90fb99a..c9829a4db 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -220,7 +220,22 @@ inline unsigned int OpCode_Size (op_code_t op) { return Is_OpCode_ESC (op) ? 2: struct number_t { void set_int (int v) { value = v; } - int to_int () const { return value; } + bool to_int (int *v) const + { + if (unlikely (!(value >= INT_MIN && value <= INT_MAX))) + { + *v = 0; + return false; + } + *v = (int) value; + return true; + } + int to_int () const + { + int v; + if (likely (to_int (&v))) return v; + return value < 0 ? INT_MIN : value > 0 ? INT_MAX : 0; + } void set_fixed (int32_t v) { value = v / 65536.0; } int32_t to_fixed () const { return value * 65536.0; } @@ -229,7 +244,7 @@ struct number_t double to_real () const { return value; } bool in_int_range () const - { return ((double) (int16_t) to_int () == value); } + { return value >= INT16_MIN && value <= INT16_MAX && (double) (int16_t) value == value; } bool operator > (const number_t &n) const { return value > n.to_real (); } bool operator < (const number_t &n) const { return n > *this; } @@ -446,7 +461,13 @@ struct arg_stack_t : cff_stack_t ARG& pop_num () { return this->pop (); } - int pop_int () { return this->pop ().to_int (); } + int pop_int () + { + int v; + if (unlikely (!this->pop ().to_int (&v))) + S::set_error (); + return v; + } unsigned int pop_uint () { From 85652028179ef4afc86010c28aacdf075dad2dcb Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 11 Jun 2026 10:27:07 +0200 Subject: [PATCH 3/3] [AAT] Size Lookup null object storage correctly The AAT Lookup null object intentionally starts with format 0xFFFF so lookup dispatch treats it as unsupported. However, its specialized null storage was declared as only two bytes, while Null(Lookup) is returned as a Lookup reference. Declare enough storage for the current Lookup object size so binding the null reference is well-defined, while preserving the invalid format bytes. Testing: meson test -C build Assisted-by: OpenAI Codex --- src/hb-aat-layout-common.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 5f4bc2352..1a35363c7 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -797,7 +797,7 @@ struct Lookup public: DEFINE_SIZE_UNION (2, format.v); }; -DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (AAT, Lookup, 2); +DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (AAT, Lookup, 13); /* * (Extended) State Table