File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -4282,12 +4282,28 @@ PHP_FUNCTION(imageresolution)
42824282 im = php_gd_libgdimageptr_from_zval_p (IM );
42834283
42844284 if (!res_x_is_null && !res_y_is_null ) {
4285+ if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL (res_x )) {
4286+ zend_argument_value_error (2 , "must be between 0 and %u" , UINT_MAX );
4287+ RETURN_THROWS ();
4288+ }
4289+ if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL (res_y )) {
4290+ zend_argument_value_error (3 , "must be between 0 and %u" , UINT_MAX );
4291+ RETURN_THROWS ();
4292+ }
42854293 gdImageSetResolution (im , res_x , res_y );
42864294 RETURN_TRUE ;
42874295 } else if (!res_x_is_null && res_y_is_null ) {
4296+ if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL (res_x )) {
4297+ zend_argument_value_error (2 , "must be between 0 and %u" , UINT_MAX );
4298+ RETURN_THROWS ();
4299+ }
42884300 gdImageSetResolution (im , res_x , res_x );
42894301 RETURN_TRUE ;
42904302 } else if (res_x_is_null && !res_y_is_null ) {
4303+ if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL (res_y )) {
4304+ zend_argument_value_error (3 , "must be between 0 and %u" , UINT_MAX );
4305+ RETURN_THROWS ();
4306+ }
42914307 gdImageSetResolution (im , res_y , res_y );
42924308 RETURN_TRUE ;
42934309 }
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Wrong image resolution
3+ --EXTENSIONS--
4+ gd
5+ --SKIPIF--
6+ <?php
7+ if (PHP_INT_SIZE != 8 ) die ("skip on non 64 bits architectures " );
8+ ?>
9+ --FILE--
10+ <?php
11+ $ filename = __DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_png.png ' ;
12+
13+ $ exp = imagecreate (100 , 100 );
14+ imagecolorallocate ($ exp , 255 , 127 , 64 );
15+
16+ $ res = imageresolution ($ exp );
17+
18+ try {
19+ imageresolution ($ exp , PHP_INT_MAX );
20+ } catch (\ValueError $ e ) {
21+ echo $ e ->getMessage () . PHP_EOL ;
22+ }
23+ try {
24+ imageresolution ($ exp , 127 , -PHP_INT_MAX );
25+ } catch (\ValueError $ e ) {
26+ echo $ e ->getMessage () . PHP_EOL ;
27+ }
28+ imageresolution ($ exp , 0 , 0 );
29+ var_dump (imageresolution ($ exp ) == $ res );
30+ ?>
31+ --EXPECTF--
32+ imageresolution(): Argument #2 ($resolution_x) must be between 0 and %d
33+ imageresolution(): Argument #3 ($resolution_y) must be between 0 and %d
34+ bool(true)
You can’t perform that action at this time.
0 commit comments