File tree Expand file tree Collapse file tree 4 files changed +66
-12
lines changed Expand file tree Collapse file tree 4 files changed +66
-12
lines changed Original file line number Diff line number Diff line change @@ -828,9 +828,14 @@ PHP_FUNCTION(imagecreatetruecolor)
828
828
return ;
829
829
}
830
830
831
- if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX ) {
832
- php_error_docref (NULL , E_WARNING , "Invalid image dimensions" );
833
- RETURN_FALSE ;
831
+ if (x_size <= 0 || x_size >= INT_MAX ) {
832
+ zend_throw_error (NULL , "Invalid width (x_size)" );
833
+ return ;
834
+ }
835
+
836
+ if (y_size <= 0 || y_size >= INT_MAX ) {
837
+ zend_throw_error (NULL , "Invalid height (y_size)" );
838
+ return ;
834
839
}
835
840
836
841
im = gdImageCreateTrueColor (x_size , y_size );
@@ -1466,9 +1471,14 @@ PHP_FUNCTION(imagecreate)
1466
1471
return ;
1467
1472
}
1468
1473
1469
- if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX ) {
1470
- php_error_docref (NULL , E_WARNING , "Invalid image dimensions" );
1471
- RETURN_FALSE ;
1474
+ if (x_size <= 0 || x_size >= INT_MAX ) {
1475
+ zend_throw_error (NULL , "Invalid width (x_size)" );
1476
+ return ;
1477
+ }
1478
+
1479
+ if (y_size <= 0 || y_size >= INT_MAX ) {
1480
+ zend_throw_error (NULL , "Invalid height (y_size)" );
1481
+ return ;
1472
1482
}
1473
1483
1474
1484
im = gdImageCreate (x_size , y_size );
Original file line number Diff line number Diff line change @@ -146,3 +146,21 @@ function save_actual_image($image)
146
146
$ filename = "{$ pathinfo ['dirname ' ]}/ {$ pathinfo ['filename ' ]}.out.png " ;
147
147
imagepng ($ image , $ filename );
148
148
}
149
+
150
+ /**
151
+ * Replicates write errors to the output log, but by catching
152
+ * and formatting exceptions instead so they have a consistent
153
+ * output
154
+ */
155
+
156
+ function trycatch_dump (...$ tests ) {
157
+ foreach ($ tests as $ test ) {
158
+ try {
159
+ var_dump ($ test ());
160
+ }
161
+ catch (\Error $ e ) {
162
+ echo '!! [ ' . get_class ($ e ) . '] ' . $ e ->getMessage () . "\n" ;
163
+ }
164
+ }
165
+ }
166
+
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Testing imagecreate(): error on out of bound parameters
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ("gd " )) die ("skip GD not present " );
6
+ if (!function_exists ("imagecreate " )) die ("skip GD Version not compatible " );
7
+ ?>
8
+ --FILE--
9
+ <?php
10
+
11
+ require __DIR__ . '/func.inc ' ;
12
+
13
+ trycatch_dump (
14
+ fn () => imagecreate (-1 , 30 ),
15
+ fn () => imagecreate (30 , -1 )
16
+ );
17
+
18
+ ?>
19
+ --EXPECT--
20
+ !! [Error] Invalid width (x_size)
21
+ !! [Error] Invalid height (y_size)
Original file line number Diff line number Diff line change @@ -9,10 +9,15 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
9
9
?>
10
10
--FILE--
11
11
<?php
12
- $ image = imagecreatetruecolor (-1 , 30 );
13
- $ image = imagecreatetruecolor (30 , -1 );
14
- ?>
15
- --EXPECTF--
16
- Warning: imagecreatetruecolor(): Invalid image dimensions in %s on line %d
17
12
18
- Warning: imagecreatetruecolor(): Invalid image dimensions in %s on line %d
13
+ require __DIR__ . '/func.inc ' ;
14
+
15
+ trycatch_dump (
16
+ fn () => imagecreatetruecolor (-1 , 30 ),
17
+ fn () => imagecreatetruecolor (30 , -1 )
18
+ );
19
+
20
+ ?>
21
+ --EXPECT--
22
+ !! [Error] Invalid width (x_size)
23
+ !! [Error] Invalid height (y_size)
You can’t perform that action at this time.
0 commit comments