@@ -3848,7 +3848,7 @@ PHP_FUNCTION(imageantialias)
3848
3848
}
3849
3849
/* }}} */
3850
3850
3851
- static bool _php_gd_zval_try_get_c_int (zval * tmp , const char * field , int * res ) {
3851
+ static bool php_gd_zval_try_get_c_int (zval * tmp , const char * field , int * res ) {
3852
3852
zend_long r ;
3853
3853
bool failed = false;
3854
3854
r = zval_try_get_long (tmp , & failed );
@@ -3882,7 +3882,7 @@ PHP_FUNCTION(imagecrop)
3882
3882
im = php_gd_libgdimageptr_from_zval_p (IM );
3883
3883
3884
3884
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (z_rect ), "x" , sizeof ("x" ) - 1 )) != NULL ) {
3885
- if (!_php_gd_zval_try_get_c_int (tmp , "x" , & rect .x )) {
3885
+ if (!php_gd_zval_try_get_c_int (tmp , "x" , & rect .x )) {
3886
3886
RETURN_THROWS ();
3887
3887
}
3888
3888
} else {
@@ -3891,7 +3891,7 @@ PHP_FUNCTION(imagecrop)
3891
3891
}
3892
3892
3893
3893
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (z_rect ), "y" , sizeof ("y" ) - 1 )) != NULL ) {
3894
- if (!_php_gd_zval_try_get_c_int (tmp , "y" , & rect .y )) {
3894
+ if (!php_gd_zval_try_get_c_int (tmp , "y" , & rect .y )) {
3895
3895
RETURN_THROWS ();
3896
3896
}
3897
3897
} else {
@@ -3900,7 +3900,7 @@ PHP_FUNCTION(imagecrop)
3900
3900
}
3901
3901
3902
3902
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (z_rect ), "width" , sizeof ("width" ) - 1 )) != NULL ) {
3903
- if (!_php_gd_zval_try_get_c_int (tmp , "width" , & rect .width )) {
3903
+ if (!php_gd_zval_try_get_c_int (tmp , "width" , & rect .width )) {
3904
3904
RETURN_THROWS ();
3905
3905
}
3906
3906
} else {
@@ -3909,14 +3909,24 @@ PHP_FUNCTION(imagecrop)
3909
3909
}
3910
3910
3911
3911
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (z_rect ), "height" , sizeof ("height" ) - 1 )) != NULL ) {
3912
- if (!_php_gd_zval_try_get_c_int (tmp , "height" , & rect .height )) {
3912
+ if (!php_gd_zval_try_get_c_int (tmp , "height" , & rect .height )) {
3913
3913
RETURN_THROWS ();
3914
3914
}
3915
3915
} else {
3916
3916
zend_argument_value_error (2 , "must have a \"height\" key" );
3917
3917
RETURN_THROWS ();
3918
3918
}
3919
3919
3920
+ if ((rect .width > 0 && rect .x > INT_MAX - rect .width ) || (rect .width < 0 && rect .x < INT_MIN - rect .width )) {
3921
+ zend_argument_value_error (2 , "overflow with \"x\" and \"width\" keys" );
3922
+ RETURN_THROWS ();
3923
+ }
3924
+
3925
+ if ((rect .height > 0 && rect .y > INT_MAX - rect .height ) || (rect .height < 0 && rect .y < INT_MIN - rect .height )) {
3926
+ zend_argument_value_error (2 , "overflow with \"y\" and \"height\" keys" );
3927
+ RETURN_THROWS ();
3928
+ }
3929
+
3920
3930
im_crop = gdImageCrop (im , & rect );
3921
3931
3922
3932
if (im_crop == NULL ) {
0 commit comments