[png] Fix potential integer overflow

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2020-06-04 22:09:11 +01:00
parent ebff21a515
commit d68befef1a

View File

@@ -924,9 +924,9 @@ static int png_pixbuf ( struct image *image, struct pixel_buffer **pixbuf ) {
/* Extract chunk header */ /* Extract chunk header */
remaining = ( image->len - png->offset ); remaining = ( image->len - png->offset );
if ( remaining < sizeof ( header ) ) { if ( remaining < ( sizeof ( header ) + sizeof ( footer ) ) ) {
DBGC ( image, "PNG %s truncated chunk header at offset " DBGC ( image, "PNG %s truncated chunk header/footer "
"%zd\n", image->name, png->offset ); "at offset %zd\n", image->name, png->offset );
rc = -EINVAL; rc = -EINVAL;
goto err_truncated; goto err_truncated;
} }
@@ -936,10 +936,10 @@ static int png_pixbuf ( struct image *image, struct pixel_buffer **pixbuf ) {
/* Validate chunk length */ /* Validate chunk length */
chunk_len = ntohl ( header.len ); chunk_len = ntohl ( header.len );
if ( remaining < ( sizeof ( header ) + chunk_len + if ( chunk_len > ( remaining - sizeof ( header ) -
sizeof ( footer ) ) ) { sizeof ( footer ) ) ) {
DBGC ( image, "PNG %s truncated chunk data/footer at " DBGC ( image, "PNG %s truncated chunk data at offset "
"offset %zd\n", image->name, png->offset ); "%zd\n", image->name, png->offset );
rc = -EINVAL; rc = -EINVAL;
goto err_truncated; goto err_truncated;
} }