From e40c0d82e2c01af4c180f7e4f8ccc4200e6a5362 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 16 Sep 2020 12:48:30 -0600 Subject: [PATCH] [ENOMEM] Handle immutable buffer in shape_full() Move the content_type changing to shape_plan_execute() where it belongs. Skip setting if content type is UNKNOWN, which happens with empty buffers only, including the immutable buffer. Alternate fix to https://github.com/harfbuzz/harfbuzz/pull/2606 and https://github.com/harfbuzz/harfbuzz/pull/2625 --- src/hb-shape-plan.cc | 55 ++++++++++++++++++++++++++++---------------- src/hb-shape.cc | 4 ---- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 666470b4f..a5a101d0f 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -355,26 +355,12 @@ hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan) } -/** - * hb_shape_plan_execute: - * @shape_plan: a shape plan. - * @font: a font. - * @buffer: a buffer. - * @features: (array length=num_features): - * @num_features: - * - * - * - * Return value: - * - * Since: 0.9.7 - **/ -hb_bool_t -hb_shape_plan_execute (hb_shape_plan_t *shape_plan, - hb_font_t *font, - hb_buffer_t *buffer, - const hb_feature_t *features, - unsigned int num_features) +static bool +_hb_shape_plan_execute_internal (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) { DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, "num_features=%d shaper_func=%p, shaper_name=%s", @@ -412,6 +398,35 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan, return false; } +/** + * hb_shape_plan_execute: + * @shape_plan: a shape plan. + * @font: a font. + * @buffer: a buffer. + * @features: (array length=num_features): + * @num_features: + * + * + * + * Return value: + * + * Since: 0.9.7 + **/ +hb_bool_t +hb_shape_plan_execute (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + bool ret = _hb_shape_plan_execute_internal (shape_plan, font, buffer, + features, num_features); + + if (ret && buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) + buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; + + return ret; +} /* diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 017fb91b6..a3debce39 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -132,8 +132,6 @@ hb_shape_full (hb_font_t *font, unsigned int num_features, const char * const *shaper_list) { - if (unlikely (hb_object_is_immutable (buffer))) return false; - hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached2 (font->face, &buffer->props, features, num_features, font->coords, font->num_coords, @@ -141,8 +139,6 @@ hb_shape_full (hb_font_t *font, hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); hb_shape_plan_destroy (shape_plan); - if (res) - buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; return res; }