diff --git a/src/OT/Layout/GPOS/PairPosFormat2.hh b/src/OT/Layout/GPOS/PairPosFormat2.hh index 15c2ab83b..8825edc38 100644 --- a/src/OT/Layout/GPOS/PairPosFormat2.hh +++ b/src/OT/Layout/GPOS/PairPosFormat2.hh @@ -182,6 +182,11 @@ struct PairPosFormat2_4 : ValueBase return_trace (c->check_range ((const void *) values, count, stride) && + /* Records of two empty ValueFormats take no bytes, so the + * range check neither bounds count nor charges for it. + * Manually modify the sanitizer max ops to take this into + * account. */ + (likely (stride) || c->check_ops (count)) && (c->lazy_some_gpos || (valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) && valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride)))); diff --git a/src/OT/Layout/GPOS/ValueFormat.hh b/src/OT/Layout/GPOS/ValueFormat.hh index 1ef0b202a..2997df0de 100644 --- a/src/OT/Layout/GPOS/ValueFormat.hh +++ b/src/OT/Layout/GPOS/ValueFormat.hh @@ -415,6 +415,12 @@ struct ValueFormat : HBUINT16 if (!c->check_range (values, count, size)) return_trace (false); + /* Records of an empty ValueFormat take no bytes, so the range check + * neither bounds count nor charges for it, while later code (eg. the + * subsetter) still walks count records. Manually modify the sanitizer + * max ops to take this into account. */ + if (unlikely (!size && !c->check_ops (count))) return_trace (false); + if (c->lazy_some_gpos) return_trace (true); diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 32420de0d..1bb9fe8ca 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -4910,6 +4910,10 @@ struct ChainRule if (unlikely (!lookahead.len.sanitize (c))) return_trace (false); hb_barrier (); const auto &lookup = StructAfter (lookahead); + /* The length checks above don't charge max_ops for the arrays they + * skipped over; charge them here so that many offsets pointing at + * the same large rule cannot escape the sanitizer's work bound. */ + if (unlikely (!c->check_ops ((const char *) &lookup - (const char *) this))) return_trace (false); return_trace (likely (lookup.sanitize (c))); } diff --git a/test/fuzzing/fonts/gpos-chainrule-shared-offsets-sanitize-ops.ttf b/test/fuzzing/fonts/gpos-chainrule-shared-offsets-sanitize-ops.ttf new file mode 100644 index 000000000..71b96a3cf Binary files /dev/null and b/test/fuzzing/fonts/gpos-chainrule-shared-offsets-sanitize-ops.ttf differ diff --git a/test/fuzzing/fonts/gpos-singlepos2-empty-valueformat-valuecount.ttf b/test/fuzzing/fonts/gpos-singlepos2-empty-valueformat-valuecount.ttf new file mode 100644 index 000000000..2ded4c306 Binary files /dev/null and b/test/fuzzing/fonts/gpos-singlepos2-empty-valueformat-valuecount.ttf differ