Skip to content

Commit

Permalink
Fix #73003: Integer Overflow in gdImageWebpCtx of gd_webp.c
Browse files Browse the repository at this point in the history
We add the missing integer overflow check to avoid potential buffer overflows.
  • Loading branch information
cmb69 committed Sep 16, 2016
1 parent 3c117d4 commit 46df064
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PHP NEWS
(cmb)
. Fixed bug #50194 (imagettftext broken on transparent background w/o
alphablending). (cmb)
. Fixed bug #73003 (Integer Overflow in gdImageWebpCtx of gd_webp.c). (trylab,
cmb)

- Mbstring:
. Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)
Expand Down
9 changes: 9 additions & 0 deletions ext/gd/libgd/gd_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization)
/* Conversion to Y,U,V buffer */
yuv_width = (width + 1) >> 1;
yuv_height = (height + 1) >> 1;

if (overflow2(width, height)) {
return;
}
/* simplification possible, because WebP must not be larger than 16384**2 */
if (overflow2(width * height, 2 * sizeof(unsigned char))) {
return;
}

yuv_nbytes = width * height + 2 * yuv_width * yuv_height;

if ((Y = (unsigned char *)gdCalloc(yuv_nbytes, sizeof(unsigned char))) == NULL) {
Expand Down

0 comments on commit 46df064

Please sign in to comment.