Skip to content

Commit 8c32be6

Browse files
committed
ext/gd: imagewebp/imageavif/imagepng stricter checks for quality/speed.
1 parent 0d913d0 commit 8c32be6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ext/gd/gd.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,22 +4113,36 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41134113
#endif
41144114
#ifdef HAVE_GD_WEBP
41154115
case PHP_GDIMG_TYPE_WEBP:
4116-
if (quality == -1) {
4116+
if (quality < -1) {
4117+
zend_argument_value_error(3, "must be at least -1");
4118+
RETURN_THROWS();
4119+
} else if (quality == -1) {
41174120
quality = 80;
41184121
}
41194122
gdImageWebpCtx(im, ctx, (int) quality);
41204123
break;
41214124
#endif
41224125
#ifdef HAVE_GD_AVIF
41234126
case PHP_GDIMG_TYPE_AVIF:
4124-
if (speed == -1) {
4127+
if (quality < -1 || quality > 100) {
4128+
zend_argument_value_error(3, "must be between -1 and 100");
4129+
RETURN_THROWS();
4130+
}
4131+
if (speed < -1 || speed > 10) {
4132+
zend_argument_value_error(4, "must be between -1 and 10");
4133+
RETURN_THROWS();
4134+
} else if (speed == -1) {
41254135
speed = 6;
41264136
}
41274137
gdImageAvifCtx(im, ctx, (int) quality, (int) speed);
41284138
break;
41294139
#endif
41304140
#ifdef HAVE_GD_PNG
41314141
case PHP_GDIMG_TYPE_PNG:
4142+
if (quality < -1 || quality > 9) {
4143+
zend_argument_value_error(3, "must be between -1 and 9");
4144+
RETURN_THROWS();
4145+
}
41324146
#ifdef HAVE_GD_BUNDLED
41334147
gdImagePngCtxEx(im, ctx, (int) quality, (int) basefilter);
41344148
#else

0 commit comments

Comments
 (0)