From 66ef3397ea9aa309bcc4478730b3ac07fd0db3ed Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Mon, 24 Aug 2026 14:57:59 +0530 Subject: [PATCH] [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. --- src/hb-ot-layout-gsubgpos.hh | 8 +++++++- .../3653331f3f13ff5b1b271c5c5583ace4c757005c | Bin 0 -> 1788 bytes 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/fuzzing/fonts/3653331f3f13ff5b1b271c5c5583ace4c757005c diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 97bb725d2..254901c2d 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -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; diff --git a/test/fuzzing/fonts/3653331f3f13ff5b1b271c5c5583ace4c757005c b/test/fuzzing/fonts/3653331f3f13ff5b1b271c5c5583ace4c757005c new file mode 100644 index 0000000000000000000000000000000000000000..de95c8528723260850eea2da6488f2b37388eea2 GIT binary patch literal 1788 zcmeHH&o2W(6#iy+HARCajX24YauBH>k*0?x6v074s2gEJ*+aK&qKAr$gFiq-gu8#h znS*d~bo2*^xJv43eQ$SL;y|4BO=jkOZ)V>6=FRSd0?>*B=op?|UYWc-zB2*s1TgG{ z<)P6`Dzgu$6nAZGI#vl0oDyFUkL~35whOQ4UBpksb9T?)UVl-HVsXkDnY%< z9=DxxMTrJ=#-Sx&+_W$ZIsYiwu_`5m*q~^GS+JZO&R6frXOK8uD(;rCh(2PQcmTqk zz4h>6ZM{AH23>!l1<#k)-Ct)_^`h#~#7f~A-E>n_d^T0jlfUMV%Ci_Sf|c6I&pkT5 z9-)aleiz|cmvIU~22*v@cg3tRt1n1=ojt};yu}#T