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/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