Promote warnings to exceptions in ext/gd

Closes GH-6023
This commit is contained in:
Máté Kocsis 2020-08-19 23:27:53 +02:00
parent 22982eee33
commit 4e6fbb0a12
No known key found for this signature in database
GPG Key ID: FD055E41728BF310
33 changed files with 95 additions and 69 deletions

View File

@ -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;
}
@ -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;
}
@ -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));
@ -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;
@ -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;
}
@ -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();
}
}
/* }}} */

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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);
@ -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);
@ -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) {
@ -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
@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -11,5 +11,5 @@ $im = imagecreatefromxbm(__DIR__ . '/libgd00094私はガラスを食べられま
var_dump($im);
?>
--EXPECTF--
Warning: imagecreatefromxbm(): '%slibgd00094私はガラスを食べられます.xbm' is not a valid XBM file in %slibgd00094-mb.php on line %d
Warning: imagecreatefromxbm(): "%slibgd00094私はガラスを食べられます.xbm" is not a valid XBM file in %slibgd00094-mb.php on line %d
bool(false)

View File

@ -11,5 +11,5 @@ $im = imagecreatefromxbm(__DIR__ . '/libgd00094.xbm');
var_dump($im);
?>
--EXPECTF--
Warning: imagecreatefromxbm(): '%slibgd00094.xbm' is not a valid XBM file in %slibgd00094.php on line %d
Warning: imagecreatefromxbm(): "%slibgd00094.xbm" is not a valid XBM file in %slibgd00094.php on line %d
bool(false)

View File

@ -14,5 +14,5 @@ var_dump($im);
Warning: imagecreatefromgd(): Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
in %slibgd00101.php on line %d
Warning: imagecreatefromgd(): '%slibgd00101.gd' is not a valid GD file in %slibgd00101.php on line %d
Warning: imagecreatefromgd(): "%slibgd00101.gd" is not a valid GD file in %slibgd00101.php on line %d
bool(false)