From 663a004d7cea1cfd896563fd61a31337d8a8545d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 16:21:26 -0600 Subject: [PATCH] [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 --- src/hb-aat-layout-common.hh | 13 +++++++++++++ src/hb-aat-layout-kerx-table.hh | 5 +++++ src/hb-aat-layout-morx-table.hh | 3 +++ 3 files changed, 21 insertions(+) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 9015371a8..23cbb0384 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -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; diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 7887cba35..f8e2987e7 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -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 (*st); c->set_lookup_index (c->lookup_index + 1); diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 7832eb873..a85ad6d4d 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -1238,6 +1238,9 @@ struct Chain bool (coverage & ChainSubtable::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;