mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-12-01 02:23:59 +01:00
[vector] Guard base64 output-length overflow in SVG image embedding
hb_vector_buf_t::append_base64() sized its output as
unsigned out_len = ((len + 2) / 3) * 4;
which overflows 32-bit for a very large len (len + 2 wraps, and the * 4
wraps for len above ~3.2 GB). len is the attacker-controlled embedded
PNG length on the vector SVG paint path (hb-vector-paint-svg.cc), so a
wrapped out_len under-sizes the buffer while the encode loop still writes
4 bytes per 3 input bytes -- a heap out-of-bounds write.
Compute the group count without the +2 (len / 3 + (len % 3 != 0)) and use
hb_unsigned_mul_overflows()/hb_unsigned_add_overflows() so an oversized
input fails the allocation instead of wrapping. resize_full() already
rejects a size that does not fit in int, so the remaining path is safe.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d75c58a2e4
commit
a439a61f8f
1 file changed
+5
-2
@@ -155,10 +155,13 @@ struct hb_vector_buf_t : hb_vector_t<char>
|
||||
|
||||
bool append_base64 (const uint8_t *data, unsigned len)
|
||||
{
|
||||
unsigned out_len = ((len + 2) / 3) * 4;
|
||||
/* Output is 4 bytes per 3 input bytes; compute without overflowing. */
|
||||
unsigned ngroups = len / 3 + (len % 3 != 0);
|
||||
unsigned out_len;
|
||||
unsigned old_len = length;
|
||||
unsigned new_len;
|
||||
if (unlikely (hb_unsigned_add_overflows (old_len, out_len, &new_len) ||
|
||||
if (unlikely (hb_unsigned_mul_overflows (ngroups, 4, &out_len) ||
|
||||
hb_unsigned_add_overflows (old_len, out_len, &new_len) ||
|
||||
!resize_dirty ((int) new_len)))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user