diff --git a/media/libpng/pngrutil.c b/media/libpng/pngrutil.c index 85386f2ad560..1f7af96df6dd 100644 --- a/media/libpng/pngrutil.c +++ b/media/libpng/pngrutil.c @@ -401,8 +401,15 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, { /* Success (maybe) - really uncompress the chunk. */ png_size_t new_size = 0; - png_charp text = png_malloc_warn(png_ptr, - prefix_size + expanded_size + 1); + png_charp text = NULL; + /* Need to check for both truncation (64-bit platforms) and integer + * overflow. + */ + if (prefix_size + expanded_size > prefix_size && + prefix_size + expanded_size < 0xffffffffU) + { + text = png_malloc_warn(png_ptr, prefix_size + expanded_size + 1); + } if (text != NULL) {