Skip to content

Fix UNKNOWN default values in stubs #6075

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 4 commits 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
44 changes: 10 additions & 34 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int le_gd_font;
#endif

#ifdef HAVE_GD_FREETYPE
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int);
#endif

#include "gd_arginfo.h"
Expand Down Expand Up @@ -3099,33 +3099,19 @@ PHP_FUNCTION(imagegetclip)
/* {{{ Give the bounding box of a text using fonts via freetype2 */
PHP_FUNCTION(imageftbbox)
{
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX);
}
/* }}} */

/* {{{ Write text to the image using fonts via freetype2 */
PHP_FUNCTION(imagefttext)
{
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
}
/* }}} */

/* {{{ Give the bounding box of a text using TrueType fonts */
PHP_FUNCTION(imagettfbbox)
{
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
}
/* }}} */

/* {{{ Write text to the image using a TrueType font */
PHP_FUNCTION(imagettftext)
{
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW);
}
/* }}} */

/* {{{ php_imagettftext_common */
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
zval *IM, *EXT = NULL;
gdImagePtr im=NULL;
Expand All @@ -3135,19 +3121,14 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
double ptsize, angle;
char *str = NULL, *fontname = NULL;
char *error = NULL;
int argc = ZEND_NUM_ARGS();
gdFTStringExtra strex = {0};

if (mode == TTFTEXT_BBOX) {
if (argc < 4 || argc > ((extended) ? 5 : 4)) {
ZEND_WRONG_PARAM_COUNT();
} else if (zend_parse_parameters(argc, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
RETURN_THROWS();
}
} else {
if (argc < 8 || argc > ((extended) ? 9 : 8)) {
ZEND_WRONG_PARAM_COUNT();
} else if (zend_parse_parameters(argc, "Oddlllss|a", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oddlllss|a", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
RETURN_THROWS();
}
im = php_gd_libgdimageptr_from_zval_p(IM);
Expand All @@ -3156,7 +3137,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
/* convert angle to radians */
angle = angle * (M_PI/180);

if (extended && EXT) { /* parse extended info */
if (EXT) { /* parse extended info */
zval *item;
zend_string *key;

Expand Down Expand Up @@ -3184,7 +3165,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int

PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");

if (extended) {
if (EXT) {
error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
} else {
error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
Expand Down Expand Up @@ -3819,15 +3800,15 @@ PHP_FUNCTION(imageaffinematrixget)
zval *tmp;
int res = GD_FALSE, i;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|z", &type, &options) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &type, &options) == FAILURE) {
RETURN_THROWS();
}

switch((gdAffineStandardMatrix)type) {
case GD_AFFINE_TRANSLATE:
case GD_AFFINE_SCALE: {
double x, y;
if (!options || Z_TYPE_P(options) != IS_ARRAY) {
if (Z_TYPE_P(options) != IS_ARRAY) {
zend_argument_type_error(1, "must be of type array when using translate or scale");
RETURN_THROWS();
}
Expand Down Expand Up @@ -3859,11 +3840,6 @@ PHP_FUNCTION(imageaffinematrixget)
case GD_AFFINE_SHEAR_VERTICAL: {
double angle;

if (!options) {
zend_argument_type_error(2, "must be of type int|float when using rotate or shear");
RETURN_THROWS();
}

angle = zval_get_double(options);

if (type == GD_AFFINE_SHEAR_HORIZONTAL) {
Expand Down
14 changes: 8 additions & 6 deletions ext/gd/gd.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ function imagesetclip(GdImage $im, int $x1, int $x2, int $y1, int $y2): bool {}
function imagegetclip(GdImage $im): array {}

#ifdef HAVE_GD_FREETYPE
function imageftbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = UNKNOWN): array|false {}
function imageftbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = []): array|false {}

function imagefttext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = UNKNOWN): array|false {}
function imagefttext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = []): array|false {}

function imagettfbbox(float $size, float $angle, string $font_file, string $text): array|false {}
/** @alias imageftbbox */
function imagettfbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = []): array|false {}

function imagettftext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text): array|false {}
/** @alias imagefttext */
function imagettftext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = []): array|false {}
#endif

/** @param array|int|float|bool $filter_args */
Expand All @@ -241,8 +243,8 @@ function imagescale(GdImage $im, int $new_width, int $new_height = -1, int $mode

function imageaffine(GdImage $im, array $affine, ?array $clip = null): GdImage|false {}

/** @param array|int|float $options */
function imageaffinematrixget(int $type, $options = UNKNOWN): array|false {}
/** @param array|float $options */
function imageaffinematrixget(int $type, $options): array|false {}

function imageaffinematrixconcat(array $m1, array $m2): array|false {}

Expand Down
36 changes: 8 additions & 28 deletions ext/gd/gd_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 540beb37f18b81102e7977447399757e865285c2 */
* Stub hash: 20849891a4907e348f1a509388ab08b0b7f6633d */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -459,7 +459,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageftbbox, 0, 4, MAY_BE_ARRAY|
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, extrainfo, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
#endif

Expand All @@ -473,30 +473,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagefttext, 0, 8, MAY_BE_ARRAY|
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, extrainfo, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
#endif

#if defined(HAVE_GD_FREETYPE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettfbbox, 0, 4, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_imagettfbbox arginfo_imageftbbox
#endif

#if defined(HAVE_GD_FREETYPE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettftext, 0, 8, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_imagettftext arginfo_imagefttext
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilter, 0, 2, _IS_BOOL, 0)
Expand Down Expand Up @@ -547,7 +533,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imageaffine, 0, 2, GdImage,
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, clip, IS_ARRAY, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageaffinematrixget, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageaffinematrixget, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -690,12 +676,6 @@ ZEND_FUNCTION(imageftbbox);
#if defined(HAVE_GD_FREETYPE)
ZEND_FUNCTION(imagefttext);
#endif
#if defined(HAVE_GD_FREETYPE)
ZEND_FUNCTION(imagettfbbox);
#endif
#if defined(HAVE_GD_FREETYPE)
ZEND_FUNCTION(imagettftext);
#endif
ZEND_FUNCTION(imagefilter);
ZEND_FUNCTION(imageconvolution);
ZEND_FUNCTION(imageflip);
Expand Down Expand Up @@ -832,10 +812,10 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(imagefttext, arginfo_imagefttext)
#endif
#if defined(HAVE_GD_FREETYPE)
ZEND_FE(imagettfbbox, arginfo_imagettfbbox)
ZEND_FALIAS(imagettfbbox, imageftbbox, arginfo_imagettfbbox)
#endif
#if defined(HAVE_GD_FREETYPE)
ZEND_FE(imagettftext, arginfo_imagettftext)
ZEND_FALIAS(imagettftext, imagefttext, arginfo_imagettftext)
#endif
ZEND_FE(imagefilter, arginfo_imagefilter)
ZEND_FE(imageconvolution, arginfo_imageconvolution)
Expand Down
55 changes: 50 additions & 5 deletions ext/gd/tests/bug67248.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,60 @@ require __DIR__ . '/func.inc';

for($i=0;$i<7;$i++) {
trycatch_dump(
fn() => imageaffinematrixget($i)
fn() => imageaffinematrixget($i, new stdClass())
);
}
?>
--EXPECT--
--EXPECTF--
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear

Notice: Object of class stdClass could not be converted to float in %s on line %d
array(6) {
[0]=>
float(%f)
[1]=>
float(%f)
[2]=>
float(%f)
[3]=>
float(%f)
[4]=>
float(0)
[5]=>
float(0)
}

Notice: Object of class stdClass could not be converted to float in %s on line %d
array(6) {
[0]=>
float(1)
[1]=>
float(0)
[2]=>
float(%f)
[3]=>
float(1)
[4]=>
float(0)
[5]=>
float(0)
}

Notice: Object of class stdClass could not be converted to float in %s on line %d
array(6) {
[0]=>
float(1)
[1]=>
float(%f)
[2]=>
float(0)
[3]=>
float(1)
[4]=>
float(0)
[5]=>
float(0)
}
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
16 changes: 8 additions & 8 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ PHP_METHOD(Phar, createDefaultStub)
zend_string *stub;
size_t index_len = 0, webindex_len = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|pp", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p!p!", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -1833,7 +1833,7 @@ PHP_METHOD(Phar, buildFromIterator)
char *base = NULL;
struct _phar_t pass;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s!", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2339,7 +2339,7 @@ PHP_METHOD(Phar, convertToExecutable)
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday, so there) */
zend_long format = 9021976, method = 9021976;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2443,7 +2443,7 @@ PHP_METHOD(Phar, convertToData)
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday so there) */
zend_long format = 9021976, method = 9021976;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2992,7 +2992,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm)
char *error, *key = NULL;
size_t key_len = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &algo, &key, &key_len) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!", &algo, &key, &key_len) != SUCCESS) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -3155,7 +3155,7 @@ PHP_METHOD(Phar, compress)
uint32_t flags;
zend_object *ret;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &method, &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!", &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -3221,7 +3221,7 @@ PHP_METHOD(Phar, decompress)
size_t ext_len = 0;
zend_object *ret;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -3804,7 +3804,7 @@ PHP_METHOD(Phar, addFile)
php_stream *resource;
zval zresource;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s!", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down
Loading