Skip to content

Promote warnings to exceptions in ext/gd #6023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,20 +861,20 @@ PHP_FUNCTION(imagecolormatch)
result = gdImageColorMatch(im1, im2);
switch (result) {
case -1:
php_error_docref(NULL, E_WARNING, "Image1 must be TrueColor" );
RETURN_FALSE;
zend_argument_value_error(1, "must be TrueColor");
RETURN_THROWS();
break;
case -2:
php_error_docref(NULL, E_WARNING, "Image2 must be Palette" );
RETURN_FALSE;
zend_argument_value_error(2, "must be Palette");
RETURN_THROWS();
break;
case -3:
php_error_docref(NULL, E_WARNING, "Image1 and Image2 must be the same size" );
RETURN_FALSE;
zend_argument_value_error(2, "must be the same size as argument #1 ($im1)");
RETURN_THROWS();
break;
case -4:
php_error_docref(NULL, E_WARNING, "Image2 must have at least one color" );
RETURN_FALSE;
zend_argument_value_error(2, "must have at least one color");
RETURN_THROWS();
break;
}

Expand Down Expand Up @@ -1459,7 +1459,7 @@ gdImagePtr _php_image_create_from_string(zend_string *data, char *tn, gdImagePtr

im = (*ioctx_func_p)(io_ctx);
if (!im) {
php_error_docref(NULL, E_WARNING, "Passed data is not in '%s' format", tn);
php_error_docref(NULL, E_WARNING, "Passed data is not in \"%s\" format", tn);
io_ctx->gd_free(io_ctx);
return NULL;
}
Expand All @@ -1483,8 +1483,8 @@ PHP_FUNCTION(imagecreatefromstring)
}

if (ZSTR_LEN(data) < sizeof(sig)) {
php_error_docref(NULL, E_WARNING, "Empty string or invalid image");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

memcpy(sig, ZSTR_VAL(data), sizeof(sig));
Expand Down Expand Up @@ -1666,7 +1666,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
return;
}

php_error_docref(NULL, E_WARNING, "'%s' is not a valid %s file", file, tn);
php_error_docref(NULL, E_WARNING, "\"%s\" is not a valid %s file", file, tn);
out_err:
php_stream_close(stream);
RETURN_FALSE;
Expand Down Expand Up @@ -1806,7 +1806,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char

fp = VCWD_FOPEN(fn, "wb");
if (!fp) {
php_error_docref(NULL, E_WARNING, "Unable to open '%s' for writing", fn);
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", fn);
RETURN_FALSE;
}

Expand Down Expand Up @@ -2297,8 +2297,8 @@ PHP_FUNCTION(imagecolorsforindex)
add_assoc_long(return_value,"blue", gdImageBlue(im,col));
add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
} else {
php_error_docref(NULL, E_WARNING, "Color index %d out of range", col);
RETURN_FALSE;
zend_argument_value_error(2, "is out of range");
RETURN_THROWS();
}
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/gd/tests/001-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ echo "Done\n";
Warning: imagecreatefrompng(%s001私はガラスを食べられます.test): Failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: imagecreatefrompng(): '%s001私はガラスを食べられます.test' is not a valid PNG file in %s on line %d
Warning: imagecreatefrompng(): "%s001私はガラスを食べられます.test" is not a valid PNG file in %s on line %d
bool(false)
Done
2 changes: 1 addition & 1 deletion ext/gd/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ echo "Done\n";
Warning: imagecreatefrompng(%s001.test): Failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: imagecreatefrompng(): '%s001.test' is not a valid PNG file in %s on line %d
Warning: imagecreatefrompng(): "%s001.test" is not a valid PNG file in %s on line %d
bool(false)
Done
2 changes: 1 addition & 1 deletion ext/gd/tests/bug37346-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Bug #37346 (gdimagecreatefromgif, bad colormap)
$im = imagecreatefromgif(__DIR__ . '/bug37346私はガラスを食べられます.gif');
?>
--EXPECTF--
Warning: imagecreatefromgif(): '%sbug37346私はガラスを食べられます.gif' is not a valid GIF file in %sbug37346-mb.php on line %d
Warning: imagecreatefromgif(): "%sbug37346私はガラスを食べられます.gif" is not a valid GIF file in %sbug37346-mb.php on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/bug37346.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Bug #37346 (gdimagecreatefromgif, bad colormap)
$im = imagecreatefromgif(__DIR__ . '/bug37346.gif');
?>
--EXPECTF--
Warning: imagecreatefromgif(): '%sbug37346.gif' is not a valid GIF file in %sbug37346.php on line %d
Warning: imagecreatefromgif(): "%sbug37346.gif" is not a valid GIF file in %sbug37346.php on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/bug37360.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ $im = imagecreatefromgif(__DIR__ . '/bug37360.gif');
var_dump($im);
?>
--EXPECTF--
Warning: imagecreatefromgif(): '%s' is not a valid GIF file in %s on line %d
Warning: imagecreatefromgif(): "%s" is not a valid GIF file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug38112.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Bug #38112 (GIF Invalid Code size ).
$im = imagecreatefromgif(__DIR__ . '/bug38112.gif');
?>
--EXPECTF--
Warning: imagecreatefromgif(): '%sbug38112.gif' is not a valid GIF file in %sbug38112.php on line %d
Warning: imagecreatefromgif(): "%sbug38112.gif" is not a valid GIF file in %sbug38112.php on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/bug39780.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Warning: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncate

Warning: imagecreatefrompng(): gd-png error: setjmp returns error condition in %s on line %d

Warning: imagecreatefrompng(): '%s' is not a valid PNG file in %s on line %d
Warning: imagecreatefrompng(): "%s" is not a valid PNG file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug39780_extern.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ var_dump($im);
--EXPECTF--
gd-png: fatal libpng error: Read Error: truncated data
gd-png error: setjmp returns error condition 2
Warning: imagecreatefrompng(): '%sbug39780.png' is not a valid PNG file in /%s on line %d
Warning: imagecreatefrompng(): v%sbug39780.png" is not a valid PNG file in /%s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug71912-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . "invalid_neg_size私はガラ
?>
OK
--EXPECTF--
Warning: imagecreatefromgd2(): '%s%einvalid_neg_size私はガラスを食べられます.gd2' is not a valid GD2 file in %s%ebug71912-mb.php on line %d
Warning: imagecreatefromgd2(): "%s%einvalid_neg_size私はガラスを食べられます.gd2" is not a valid GD2 file in %s%ebug71912-mb.php on line %d
OK
2 changes: 1 addition & 1 deletion ext/gd/tests/bug71912.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . "invalid_neg_size.gd2");
?>
OK
--EXPECTF--
Warning: imagecreatefromgd2(): '%s%einvalid_neg_size.gd2' is not a valid GD2 file in %s%ebug71912.php on line %d
Warning: imagecreatefromgd2(): "%s%einvalid_neg_size.gd2" is not a valid GD2 file in %s%ebug71912.php on line %d
OK
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72339.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ unlink($fname);
Warning: imagecreatefromgd2(): Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
in %sbug72339.php on line %d

Warning: imagecreatefromgd2(): '%sbug72339.gd' is not a valid GD2 file in %sbug72339.php on line %d
Warning: imagecreatefromgd2(): "%sbug72339.gd" is not a valid GD2 file in %sbug72339.php on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/bug73161.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ $im = imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73161.gd2');
var_dump($im);
?>
--EXPECTF--
Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug73868.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73868.gd2'));
Warning: imagecreatefromgd2(): gd2: EOF while reading
in %s on line %d

Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)
4 changes: 2 additions & 2 deletions ext/gd/tests/bug73869.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73869a.gd2'));
var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73869b.gd2'));
?>
--EXPECTF--
Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)

Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug75111.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $str .= hex2bin("01001800000000000000000000000000000000000000000000000000");
var_dump(imagecreatefromstring($str));
?>
--EXPECTF--
Warning: imagecreatefromstring(): Passed data is not in 'BMP' format in %s on line %d
Warning: imagecreatefromstring(): Passed data is not in "BMP" format in %s on line %d

Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug75571.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ if (!extension_loaded('gd')) die('skip gd extension not available');
var_dump(imagecreatefromgif(__DIR__ . '/bug75571.gif'));
?>
--EXPECTF--
Warning: imagecreatefromgif(): '%s' is not a valid GIF file in %s on line %d
Warning: imagecreatefromgif(): "%s" is not a valid GIF file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/bug77195.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ imagecreatefromjpeg($filename);
--EXPECTF--
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: JPEG datastream contains no image in %s on line %d

Warning: imagecreatefromjpeg(): '%s' is not a valid JPEG file in %s on line %d
Warning: imagecreatefromjpeg(): "%s" is not a valid JPEG file in %s on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/bug77973.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var_dump($im);
--EXPECTF--
Warning: imagecreatefromxbm(): Invalid XBM in %s on line %d

Warning: imagecreatefromxbm(): '%s' is not a valid XBM file in %s on line %d
Warning: imagecreatefromxbm(): "%s" is not a valid XBM file in %s on line %d
bool(false)
--CLEAN--
<?php
Expand Down
22 changes: 13 additions & 9 deletions ext/gd/tests/colorclosest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ imagedestroy($im);

$im = imagecreate(5,5);
$c = imagecolorclosest($im, 255,0,255);
print_r(imagecolorsforindex($im, $c));
try {
imagecolorsforindex($im, $c);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
imagedestroy($im);

$im = imagecreate(5,5);
Expand Down Expand Up @@ -48,7 +52,11 @@ imagedestroy($im);

$im = imagecreate(5,5);
$c = imagecolorclosestalpha($im, 255,0,255,100);
print_r(imagecolorsforindex($im, $c));
try {
imagecolorsforindex($im, $c);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
imagedestroy($im);

$im = imagecreate(5,5);
Expand All @@ -62,7 +70,6 @@ for ($i=0; $i<255; $i++) imagecolorresolvealpha($im, $i,0,0,1);
$c = imagecolorclosestalpha($im, 255,0,0,1);
print_r(imagecolorsforindex($im, $c));


$im = imagecreate(5,5);
for ($i=0; $i<256; $i++) {
if ($i == 246) {
Expand All @@ -74,12 +81,10 @@ for ($i=0; $i<256; $i++) {
$c = imagecolorclosestalpha($im, 255,10,10,1);
print_r(imagecolorsforindex($im, $c));


?>
--EXPECTF--
--EXPECT--
FF00FF

Warning: imagecolorsforindex(): Color index -1 out of range in %s on line %d
imagecolorsforindex(): Argument #2 ($index) is out of range
Array
(
[red] => 255
Expand All @@ -102,8 +107,7 @@ Array
[alpha] => 0
)
64FF00FF

Warning: imagecolorsforindex(): Color index -1 out of range in %s on line %d
imagecolorsforindex(): Argument #2 ($index) is out of range
Array
(
[red] => 255
Expand Down
10 changes: 7 additions & 3 deletions ext/gd/tests/colormatch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ imagecolormatch
$im = imagecreatetruecolor(5,5);
$im2 = imagecreate(5,5);

imagecolormatch($im, $im2);
try {
imagecolormatch($im, $im2);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

echo "ok\n";

imagedestroy($im);
?>
--EXPECTF--
Warning: imagecolormatch(): Image2 must have at least one color in %s on line %d
--EXPECT--
imagecolormatch(): Argument #2 ($im2) must have at least one color
ok
2 changes: 1 addition & 1 deletion ext/gd/tests/crafted_gd2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Test max colors for a gd image.
imagecreatefromgd(__DIR__ . '/crafted.gd2');
?>
--EXPECTF--
Warning: imagecreatefromgd(): '%scrafted.gd2' is not a valid GD file in %s on line %d
Warning: imagecreatefromgd(): "%scrafted.gd2" is not a valid GD file in %s on line %d
9 changes: 6 additions & 3 deletions ext/gd/tests/createfromstring.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ unlink($dir . '/p.png');


//empty string
$im = imagecreatefromstring('');
try {
imagecreatefromstring('');
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
//random string > 12
$im = imagecreatefromstring(' asdf jklp foo');
?>
--EXPECTF--
createfromstring truecolor png: ok
createfromstring palette png: ok

Warning: imagecreatefromstring(): Empty string or invalid image in %screatefromstring.php on line %d
imagecreatefromstring(): Argument #1 ($image) cannot be empty

Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/createfromwbmp2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ unlink($filename);
Warning: imagecreatefromwbmp(): Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
in %s on line %d

Warning: imagecreatefromwbmp(): '%s' is not a valid WBMP file in %s on line %d
Warning: imagecreatefromwbmp(): "%s" is not a valid WBMP file in %s on line %d
2 changes: 1 addition & 1 deletion ext/gd/tests/createfromwbmp2_extern.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ unlink($filename);
--EXPECTF--
gd warning: Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully

Warning: imagecreatefromwbmp(): '%s_tmp.wbmp' is not a valid WBMP file in %s on line %d
Warning: imagecreatefromwbmp(): "%s_tmp.wbmp" is not a valid WBMP file in %s on line %d
13 changes: 9 additions & 4 deletions ext/gd/tests/imagecolormatch_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ $ima = imagecreate(110, 20);
$background_color = imagecolorallocate($ima, 0, 0, 0);
$imb = imagecreate(110, 20);
$background_color = imagecolorallocate($imb, 0, 0, 100);
var_dump(imagecolormatch($ima, $imb));

try {
imagecolormatch($ima, $imb);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: imagecolormatch(): Image1 must be TrueColor in %s on line %d
bool(false)
--EXPECT--
imagecolormatch(): Argument #1 ($im1) must be TrueColor
13 changes: 9 additions & 4 deletions ext/gd/tests/imagecolormatch_error3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ $ima = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($ima, 0, 0, 0);
$imb = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($imb, 0, 0, 100);
var_dump(imagecolormatch($ima, $imb));

try {
imagecolormatch($ima, $imb);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: imagecolormatch(): Image2 must be Palette in %s on line %d
bool(false)
--EXPECT--
imagecolormatch(): Argument #2 ($im2) must be Palette
13 changes: 9 additions & 4 deletions ext/gd/tests/imagecolormatch_error4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ $ima = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($ima, 0, 0, 0);
$imb = imagecreate(100, 20);
$background_color = imagecolorallocate($imb, 0, 0, 100);
var_dump(imagecolormatch($ima, $imb));

try {
imagecolormatch($ima, $imb);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: imagecolormatch(): Image1 and Image2 must be the same size in %s on line %d
bool(false)
--EXPECT--
imagecolormatch(): Argument #2 ($im2) must be the same size as argument #1 ($im1)
2 changes: 1 addition & 1 deletion ext/gd/tests/libgd00086.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Warning: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncate

Warning: imagecreatefrompng(): gd-png error: setjmp returns error condition in %s on line %d

Warning: imagecreatefrompng(): '%s' is not a valid PNG file in %s on line %d
Warning: imagecreatefrompng(): "%s" is not a valid PNG file in %s on line %d
bool(false)
2 changes: 1 addition & 1 deletion ext/gd/tests/libgd00086_extern.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var_dump($im);
gd-png: fatal libpng error: Read Error: truncated data
gd-png error: setjmp returns error condition 1

Warning: imagecreatefrompng(): '%slibgd00086.png' is not a valid PNG file in %s on line %d
Warning: imagecreatefrompng(): "%slibgd00086.png" is not a valid PNG file in %s on line %d
bool(false)
Loading