[aat] Charge each applied kerx/kern/morx subtable pass to max_ops

KerxTable::apply() (shared by kerx and both kern flavours) and morx
Chain::apply() run one full pass over the buffer per subtable, but a
pass that changes nothing never touched buffer->max_ops, so a font
could ask for an unbounded number of passes -- and morx may first
grow the buffer up to 256x, so each pass is over a much larger buffer
than the input.  The kerx loop also ignored buffer->successful.

Add hb_aat_apply_context_t::charge_buffer_pass(), which debits
buffer->len from max_ops using the same decrement/check/
successful=false idiom as morx glyph insertion and hb_buffer_t, and
call it in both subtable loops right before a subtable is applied;
skipped subtables (wrong direction, no glyph intersection) stay free.
Placing the charge in the shared apply context covers kerx, OT kern,
Apple kern and morx with one helper.  Also stop the kerx loop once the
buffer is no longer successful, as the morx loop already does.

This complements the subtable-count cap: that bounds the per-face
accelerator memory, while this bounds the per-shape pass work,
including passes over a buffer that morx has grown.  Real fonts apply
a few subtables over a buffer far shorter than the budget, so they are
unaffected.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-KCOERIUT.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.8 committed 2026-11-02 10:51:40 -06:00
1 parent cf9889b73f
commit 663a004d7c
3 files changed
+21

No files matched your search

+13
View File
@@ -166,6 +166,19 @@ struct hb_aat_apply_context_t :
buffer_is_reversed = !buffer_is_reversed;
}
/* Applying a subtable walks the whole buffer. The font controls the
* number of subtables, so charge each pass to the buffer's work budget. */
HB_NODISCARD bool charge_buffer_pass ()
{
buffer->max_ops -= buffer->len;
if (unlikely (buffer->max_ops < 0))
{
buffer->successful = false;
return false;
}
return true;
}
void setup_buffer_glyph_set ()
{
using_buffer_glyph_set = buffer->len >= 4 && buffer_glyph_set;
+5
View File
@@ -1087,6 +1087,9 @@ struct KerxTable
reverse = bool (st->u.header.coverage & st->u.header.Backwards) !=
HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction);
if (unlikely (!c->charge_buffer_pass ()))
break;
if (!c->buffer->message (c->font, "start subtable %u", c->lookup_index))
goto skip;
@@ -1118,6 +1121,8 @@ struct KerxTable
(void) c->buffer->message (c->font, "end subtable %u", c->lookup_index);
if (unlikely (!c->buffer->successful)) break;
skip:
st = &StructAfter<SubTable> (*st);
c->set_lookup_index (c->lookup_index + 1);
+3
View File
@@ -1238,6 +1238,9 @@ struct Chain
bool (coverage & ChainSubtable<Types>::Backwards) !=
HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction);
if (unlikely (!c->charge_buffer_pass ()))
break;
if (!c->buffer->message (c->font, "start chainsubtable %u", c->lookup_index))
goto skip;