diff --git a/src/hb-vector-buf.hh b/src/hb-vector-buf.hh index d09f907de..543cbddd7 100644 --- a/src/hb-vector-buf.hh +++ b/src/hb-vector-buf.hh @@ -46,7 +46,9 @@ struct hb_vector_buf_t : hb_vector_t bool append_len (const char *s, unsigned l) { unsigned old_len = length; - if (unlikely (!resize_dirty ((int) (old_len + l)))) + unsigned new_len; + if (unlikely (hb_unsigned_add_overflows (old_len, l, &new_len) || + !resize_dirty ((int) new_len))) return false; hb_memcpy (arrayZ + old_len, s, l); return true; @@ -155,7 +157,9 @@ struct hb_vector_buf_t : hb_vector_t { unsigned out_len = ((len + 2) / 3) * 4; unsigned old_len = length; - if (unlikely (!resize_dirty ((int) (old_len + out_len)))) + unsigned new_len; + if (unlikely (hb_unsigned_add_overflows (old_len, out_len, &new_len) || + !resize_dirty ((int) new_len))) return false; char *dst = arrayZ + old_len; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index e831c72b4..7f0b454d2 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -635,7 +635,9 @@ struct hb_vector_t HB_ALWAYS_INLINE_VECTOR_ALLOCS bool resize_full (int size_, bool initialize, bool exact) { - unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; + if (unlikely (size_ < 0)) + return false; + unsigned int size = (unsigned int) size_; if (!alloc (size, exact)) return false;