[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 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 5.5 authored and GitHub committed 2026-11-09 20:25:53 -06:00
1 parent 73e9d5f054
commit 5ac43f0a80
2 files changed
+12 -11

No files matched your search

+2 -10
View File
@@ -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
+10 -1
View File
@@ -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));