[shape] Fail shaping internally if buffer ops exceeded

This commit is contained in:
Behdad Esfahbod 2022-06-01 04:54:18 -06:00
parent 5a058ba158
commit e246723f0c
3 changed files with 11 additions and 3 deletions

View File

@ -311,6 +311,7 @@ hb_buffer_t::enter ()
{ {
deallocate_var_all (); deallocate_var_all ();
serial = 0; serial = 0;
shaping_failed = false;
scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_LEN_FACTOR))) if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_LEN_FACTOR)))
{ {
@ -330,6 +331,7 @@ hb_buffer_t::leave ()
max_ops = HB_BUFFER_MAX_OPS_DEFAULT; max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
deallocate_var_all (); deallocate_var_all ();
serial = 0; serial = 0;
// Intentionally not reseting shaping_failed, such that it can be inspected.
} }

View File

@ -1159,8 +1159,6 @@ hb_propagate_flags (hb_buffer_t *buffer)
static void static void
hb_ot_shape_internal (hb_ot_shape_context_t *c) hb_ot_shape_internal (hb_ot_shape_context_t *c)
{ {
c->buffer->enter ();
/* Save the original direction, we use it later. */ /* Save the original direction, we use it later. */
c->target_direction = c->buffer->props.direction; c->target_direction = c->buffer->props.direction;

View File

@ -129,6 +129,8 @@ hb_shape_full (hb_font_t *font,
if (unlikely (!buffer->len)) if (unlikely (!buffer->len))
return true; return true;
buffer->enter ();
hb_buffer_t *text_buffer = nullptr; hb_buffer_t *text_buffer = nullptr;
if (buffer->flags & HB_BUFFER_FLAG_VERIFY) if (buffer->flags & HB_BUFFER_FLAG_VERIFY)
{ {
@ -140,8 +142,12 @@ hb_shape_full (hb_font_t *font,
features, num_features, features, num_features,
font->coords, font->num_coords, font->coords, font->num_coords,
shaper_list); shaper_list);
buffer->shaping_failed = false;
hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features);
if (buffer->max_ops <= 0)
buffer->shaping_failed = true;
hb_shape_plan_destroy (shape_plan); hb_shape_plan_destroy (shape_plan);
if (text_buffer) if (text_buffer)
@ -157,6 +163,8 @@ hb_shape_full (hb_font_t *font,
hb_buffer_destroy (text_buffer); hb_buffer_destroy (text_buffer);
} }
buffer->leave ();
return res; return res;
} }