From 5cbce05a7cfb5b3423e32feb19341730fd5ef363 Mon Sep 17 00:00:00 2001 From: jfkthame Date: Tue, 7 Apr 2026 22:36:21 +0100 Subject: [PATCH] Add a couple of missing overflow checks (#5901) * Use hb_unsigned_mul_overflows in CFF2 process_blend. * Check for overflow when computing hb_aat_layout_chain_accelerator_t size. --- src/hb-aat-layout-morx-table.hh | 13 ++++++++++--- src/hb-cff2-interp-cs.hh | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index c25833cf2..312f0cd10 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -987,9 +987,16 @@ struct hb_aat_layout_chain_accelerator_t { unsigned count = chain.get_subtable_count (); - unsigned size = sizeof (hb_aat_layout_chain_accelerator_t) - - HB_VAR_ARRAY * sizeof (hb_accelerate_subtables_context_t::hb_applicable_t) + - count * sizeof (hb_accelerate_subtables_context_t::hb_applicable_t); + unsigned product; + if (unlikely (hb_unsigned_mul_overflows (count, + sizeof (hb_accelerate_subtables_context_t::hb_applicable_t), &product))) + return nullptr; + + unsigned size; + if (unlikely (hb_unsigned_add_overflows (sizeof (hb_aat_layout_chain_accelerator_t) - + HB_VAR_ARRAY * sizeof (hb_accelerate_subtables_context_t::hb_applicable_t), product, &size))) { + return nullptr; + } /* The following is a calloc because when we are collecting subtables, * some of them might be invalid and hence not collect; as a result, diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index b69bb7fdb..6a338b462 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -281,13 +281,14 @@ struct cff2_cs_opset_t : cs_opset_t, PAR k = env.get_region_count (); n = env.argStack.pop_uint (); /* copy the blend values into blend array of the default values */ - unsigned int start = env.argStack.get_count () - ((k+1) * n); - /* let an obvious error case fail, but note CFF2 spec doesn't forbid n==0 */ - if (unlikely (start > env.argStack.get_count ())) + unsigned int count = env.argStack.get_count (); + unsigned int total; + if (unlikely (hb_unsigned_mul_overflows (k + 1, n, &total) || total > count)) { env.set_error (); return; } + unsigned int start = count - total; for (unsigned int i = 0; i < n; i++) { const hb_array_t blends = env.argStack.sub_array (start + n + (i * k), k);