From 5ac43f0a8019f28014f45642af9a7ec094b1bb23 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 Nov 2026 20:25:53 -0600 Subject: [PATCH] [buffer] Restore plain enter() limits; inject the graphite2 fault in the test (#6614) Follow-up to #6511. Moving enter()/leave() into HB_SHAPER_EXECUTE (so hb_shape_plan_execute() gets per-text max_len/max_ops, the ANT-2026-SUMXXLXH fix) made enter() overwrite the max_len that test-graphite2-buffer narrows to inject an output-growth failure. #6511 worked around that in the library: enter() kept any limit already below the idle default. That is extra logic in every shape for the sake of one test. Restore enter() to simply compute the per-text limits, and have the test call the plan's shaper_func directly in the failing iteration, so the max_len it sets is not replaced. enter()/leave() stay in HB_SHAPER_EXECUTE, so hb_shape_plan_execute() remains bounded. The verify path in hb_shape_full() now runs after leave(); that is fine: verify only reads the shaped buffer's info/pos and shapes fresh buffers through hb_shape_full(), each of which gets its own enter()/leave(). It uses no buffer vars or work limits of the outer buffer. Tested: meson test -C build (278/278 pass), and a second build with -Dgraphite2=enabled (280/280 pass, incl. test-graphite2-buffer). Co-authored-by: Claude Opus 5.5 --- src/hb-buffer.cc | 12 ++---------- src/test-graphite2-buffer.cc | 11 ++++++++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 191844d2e..06c3aaf23 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -328,22 +328,14 @@ hb_buffer_t::enter () deallocate_var_all (); serial = 0; scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; - /* enter() now runs on every shape, including hb_shape_plan_execute(). - * Compute the per-text limit as before, but if internal code has already - * narrowed a limit below the idle default (e.g. the fault injection in - * test-graphite2-buffer), keep the stricter value. Public paths always - * arrive at the defaults (from hb_buffer_create() / leave()), so they get - * the computed per-text limit unchanged. */ unsigned mul; if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_LEN_FACTOR, &mul))) { - unsigned limit = hb_max (mul, (unsigned) HB_BUFFER_MAX_LEN_MIN); - max_len = max_len < HB_BUFFER_MAX_LEN_DEFAULT ? hb_min (max_len, limit) : limit; + max_len = hb_max (mul, (unsigned) HB_BUFFER_MAX_LEN_MIN); } if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_OPS_FACTOR, &mul))) { - int limit = (int) hb_max (mul, (unsigned) HB_BUFFER_MAX_OPS_MIN); - max_ops = max_ops < HB_BUFFER_MAX_OPS_DEFAULT ? hb_min (max_ops, limit) : limit; + max_ops = hb_max (mul, (unsigned) HB_BUFFER_MAX_OPS_MIN); } } void diff --git a/src/test-graphite2-buffer.cc b/src/test-graphite2-buffer.cc index 89a2731b1..b4ec6613e 100644 --- a/src/test-graphite2-buffer.cc +++ b/src/test-graphite2-buffer.cc @@ -23,6 +23,7 @@ */ #include "hb-buffer.hh" +#include "hb-shape-plan.hh" int main (int argc, char **argv) @@ -49,10 +50,18 @@ main (int argc, char **argv) * Refuse output growth without depending on system memory pressure. */ hb_always_assert (buffer->allocated < 164); hb_always_assert (buffer->allocated * sizeof (hb_glyph_position_t) >= 4 * 24 + 164 * 8); + bool ret; if (fail) + { + /* hb_shape_plan_execute() installs its own per-text max_len; + * call the shaper directly so the stricter limit sticks. */ buffer->max_len = buffer->allocated; + ret = plan->key.shaper_func (plan, font, buffer, nullptr, 0); + } + else + ret = hb_shape_plan_execute (plan, font, buffer, nullptr, 0); - hb_always_assert (bool (hb_shape_plan_execute (plan, font, buffer, nullptr, 0)) == !fail); + hb_always_assert (ret == !fail); hb_always_assert (bool (hb_buffer_allocation_successful (buffer)) == !fail); hb_always_assert (hb_buffer_get_length (buffer) == (fail ? 4u : 164u));