[depend] Bound context inputCount to HB_MAX_CONTEXT_LENGTH

context_depend_recurse_lookups tracks covered sequence positions in
a fixed hb_bit_page_t, but the dependency-graph path never bounded
inputCount the way the shaping apply path does. A crafted GSUB
contextual rule with glyphCount past the page (e.g. 512) and a
SubstLookupRecord whose sequenceIndex lands in a higher page element
than endIndex makes hb_bit_page_t::add_range compute its memset
length as (char*)lb - (char*)la, which is negative and wraps to a
huge size_t, writing past the stack-allocated page. Reachable from
hb_subset_depend_from_face_or_fail on a crafted face.

Cap inputCount at HB_MAX_CONTEXT_LENGTH before the page is used,
matching the apply path; rules longer than that never apply during
shaping, so no real dependency edges are lost. Adds a regression
seed exercised by the depend fuzzer.
This commit is contained in:
nussaiba shaikh committed 2026-08-24 14:57:59 +05:30
1 parent 485df9d575
commit 66ef3397ea
2 files changed
+7 -1

No files matched your search

+7 -1
View File
@@ -2399,7 +2399,13 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c,
* - Sequential accumulation: Not done. We want ALL possible edges, so we don't
* limit later lookups based on outputs from earlier lookups in the same rule. */
/* HB_MAX_CONTEXT_LENGTH positions fit in one allocation-free bit page. */
/* Sequence positions are tracked in one allocation-free bit page below.
* A rule longer than HB_MAX_CONTEXT_LENGTH never applies during shaping
* (the apply path rejects it), so skip it here instead of running past
* the fixed page in add_range(). */
if (unlikely (inputCount > HB_MAX_CONTEXT_LENGTH))
return;
hb_bit_page_t covered_seq_indices;
hb_set_t &pos_glyphs = scratch->pos_glyphs;
hb_set_t &position_context = scratch->position_context;