The per-shaper lazy loaders (hb_shaper_lazy_loader_t) declare nullptr
as their null object, so hb_lazy_loader_t::get_stored() cannot tell
"create() failed" from "not created yet" and re-runs create() on
every access. hb_shape_plan_key_t::init() tests face->data.graphite2
before the plan cache is consulted, so a font whose Silf table
Graphite2 rejects paid a full gr_make_face_with_ops() on every
hb_shape() call for the life of the face -- CPU cost unbounded by
max_ops/max_len, which apply only once the buffer is processed.
The loader already has the mechanism for this: tag_null stores a
failed create() as get_null() with bit 0 set, and get_stored()/
operator bool()/do_destroy() mask or recognize it by that bit.
Opt the shaper loaders into tag_null, fixing every shaper's face and
font data at once, as the table and accelerator loaders already do.
HB_SHAPER_DATA_SUCCEEDED moves from (void *) +1 to (void *) +2 so the
success sentinel no longer collides with the tagged null (nullptr | 1
== (void *) 1); its no-op destroy functions never dereference it.
hb_font_t's data.fini() on font changes still resets the font-data
loaders, so a retry happens there. A font with no Silf table is now
also asked for it once per face instead of once per call.
Adds test_graphite2_failed_face_load_is_remembered, which counts Silf
table requests across three hb_shape() calls; it fails on the
unpatched tree (8 != 4) and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LPR3RSMJ.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Every shaper that returns true must leave the buffer with
have_positions set; the OpenType and fallback shapers call
clear_positions() unconditionally. _hb_graphite2_shape() borrows
pos[] as scratch via get_scratch_buffer(), which clears
have_positions, and the normal path restores it through
hb_buffer_get_glyph_positions(). But when Graphite deletes every
glyph of the run, the zero-slot early-out set buffer->len = 0 and
returned true without restoring the flag, so a later
hb_buffer_normalize_glyphs() (hb-shape --normalize-glyphs) hit
assert (buffer->have_positions) and aborted.
Restore the invariant where it is broken, by calling
buffer->clear_positions() in the empty-segment return.
Adds test_graphite2_all_glyphs_deleted, with an embedded 500-byte
font whose Silf rule deletes 'a'; shaping "aaa" must now succeed with
length 0 and positions, while the "aba" control is unchanged.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-BG9QJRVN.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_hb_graphite2_shape() grows buffer->info with ensure() (a plain
realloc) and then fills each output glyph field by field, but never
assigned hb_glyph_info_t::mask. Entries beyond the original text
length therefore kept uninitialised heap bytes (or, in a reused
buffer, the mask from a previous shaping run); clear_glyph_flags()
only rewrites the low three bits, so hb_buffer_get_glyph_infos()
handed the stale bits 3-31 to the caller. Shaping output is correct
(every in-tree reader masks down to HB_GLYPH_FLAG_DEFINED), but
valgrind/MSan flag the uninitialised bytes and code reading the
private field sees values that vary run to run.
Set info->mask = 0 in the fill loop, next to the other fields. That
matches what hb_buffer_t::add() starts from and what the OpenType
shaper returns after hb_propagate_flags(), so the subsequent
clear_glyph_flags()/unsafe_to_break() operate on a defined value and
shaping output is unchanged. No other shaper needs the change.
Adds test_graphite2_inserted_glyph_masks, which first runs the
OpenType shaper so a removed default-ignorable leaves a non-zero mask
in the buffer storage, then checks that every glyph the Graphite
shaper adds for U+0622 comes back with nothing but glyph-flag bits.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-UDVJURW0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.
Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.
HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.
Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.
Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build
Assisted-by: Codex <codex@openai.com>
Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>