Skip to content

Commit 628db3f

Browse files
committed
Fix UNKNOWN default values in various extensions
Closes GH-6075
1 parent 2c96780 commit 628db3f

26 files changed

+188
-187
lines changed

ext/gd/gd.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int le_gd_font;
8686
#endif
8787

8888
#ifdef HAVE_GD_FREETYPE
89-
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
89+
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int);
9090
#endif
9191

9292
#include "gd_arginfo.h"
@@ -3099,33 +3099,19 @@ PHP_FUNCTION(imagegetclip)
30993099
/* {{{ Give the bounding box of a text using fonts via freetype2 */
31003100
PHP_FUNCTION(imageftbbox)
31013101
{
3102-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
3102+
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX);
31033103
}
31043104
/* }}} */
31053105

31063106
/* {{{ Write text to the image using fonts via freetype2 */
31073107
PHP_FUNCTION(imagefttext)
31083108
{
3109-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
3110-
}
3111-
/* }}} */
3112-
3113-
/* {{{ Give the bounding box of a text using TrueType fonts */
3114-
PHP_FUNCTION(imagettfbbox)
3115-
{
3116-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
3117-
}
3118-
/* }}} */
3119-
3120-
/* {{{ Write text to the image using a TrueType font */
3121-
PHP_FUNCTION(imagettftext)
3122-
{
3123-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
3109+
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW);
31243110
}
31253111
/* }}} */
31263112

31273113
/* {{{ php_imagettftext_common */
3128-
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
3114+
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
31293115
{
31303116
zval *IM, *EXT = NULL;
31313117
gdImagePtr im=NULL;
@@ -3135,19 +3121,14 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31353121
double ptsize, angle;
31363122
char *str = NULL, *fontname = NULL;
31373123
char *error = NULL;
3138-
int argc = ZEND_NUM_ARGS();
31393124
gdFTStringExtra strex = {0};
31403125

31413126
if (mode == TTFTEXT_BBOX) {
3142-
if (argc < 4 || argc > ((extended) ? 5 : 4)) {
3143-
ZEND_WRONG_PARAM_COUNT();
3144-
} else if (zend_parse_parameters(argc, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
3127+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
31453128
RETURN_THROWS();
31463129
}
31473130
} else {
3148-
if (argc < 8 || argc > ((extended) ? 9 : 8)) {
3149-
ZEND_WRONG_PARAM_COUNT();
3150-
} 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) {
3131+
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) {
31513132
RETURN_THROWS();
31523133
}
31533134
im = php_gd_libgdimageptr_from_zval_p(IM);
@@ -3156,7 +3137,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31563137
/* convert angle to radians */
31573138
angle = angle * (M_PI/180);
31583139

3159-
if (extended && EXT) { /* parse extended info */
3140+
if (EXT) { /* parse extended info */
31603141
zval *item;
31613142
zend_string *key;
31623143

@@ -3184,7 +3165,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31843165

31853166
PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
31863167

3187-
if (extended) {
3168+
if (EXT) {
31883169
error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
31893170
} else {
31903171
error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
@@ -3819,15 +3800,15 @@ PHP_FUNCTION(imageaffinematrixget)
38193800
zval *tmp;
38203801
int res = GD_FALSE, i;
38213802

3822-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|z", &type, &options) == FAILURE) {
3803+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &type, &options) == FAILURE) {
38233804
RETURN_THROWS();
38243805
}
38253806

38263807
switch((gdAffineStandardMatrix)type) {
38273808
case GD_AFFINE_TRANSLATE:
38283809
case GD_AFFINE_SCALE: {
38293810
double x, y;
3830-
if (!options || Z_TYPE_P(options) != IS_ARRAY) {
3811+
if (Z_TYPE_P(options) != IS_ARRAY) {
38313812
zend_argument_type_error(1, "must be of type array when using translate or scale");
38323813
RETURN_THROWS();
38333814
}
@@ -3859,11 +3840,6 @@ PHP_FUNCTION(imageaffinematrixget)
38593840
case GD_AFFINE_SHEAR_VERTICAL: {
38603841
double angle;
38613842

3862-
if (!options) {
3863-
zend_argument_type_error(2, "must be of type int|float when using rotate or shear");
3864-
RETURN_THROWS();
3865-
}
3866-
38673843
angle = zval_get_double(options);
38683844

38693845
if (type == GD_AFFINE_SHEAR_HORIZONTAL) {

ext/gd/gd.stub.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,15 @@ function imagesetclip(GdImage $im, int $x1, int $x2, int $y1, int $y2): bool {}
215215
function imagegetclip(GdImage $im): array {}
216216

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

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

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

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

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

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

244-
/** @param array|int|float $options */
245-
function imageaffinematrixget(int $type, $options = UNKNOWN): array|false {}
246+
/** @param array|float $options */
247+
function imageaffinematrixget(int $type, $options): array|false {}
246248

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

ext/gd/gd_arginfo.h

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 540beb37f18b81102e7977447399757e865285c2 */
2+
* Stub hash: 20849891a4907e348f1a509388ab08b0b7f6633d */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -459,7 +459,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageftbbox, 0, 4, MAY_BE_ARRAY|
459459
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
460460
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
461461
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
462-
ZEND_ARG_TYPE_INFO(0, extrainfo, IS_ARRAY, 0)
462+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
463463
ZEND_END_ARG_INFO()
464464
#endif
465465

@@ -473,30 +473,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagefttext, 0, 8, MAY_BE_ARRAY|
473473
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
474474
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
475475
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
476-
ZEND_ARG_TYPE_INFO(0, extrainfo, IS_ARRAY, 0)
476+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
477477
ZEND_END_ARG_INFO()
478478
#endif
479479

480480
#if defined(HAVE_GD_FREETYPE)
481-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettfbbox, 0, 4, MAY_BE_ARRAY|MAY_BE_FALSE)
482-
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
483-
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
484-
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
485-
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
486-
ZEND_END_ARG_INFO()
481+
#define arginfo_imagettfbbox arginfo_imageftbbox
487482
#endif
488483

489484
#if defined(HAVE_GD_FREETYPE)
490-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettftext, 0, 8, MAY_BE_ARRAY|MAY_BE_FALSE)
491-
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
492-
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
493-
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
494-
ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0)
495-
ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0)
496-
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
497-
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
498-
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
499-
ZEND_END_ARG_INFO()
485+
#define arginfo_imagettftext arginfo_imagefttext
500486
#endif
501487

502488
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilter, 0, 2, _IS_BOOL, 0)
@@ -547,7 +533,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imageaffine, 0, 2, GdImage,
547533
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, clip, IS_ARRAY, 1, "null")
548534
ZEND_END_ARG_INFO()
549535

550-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageaffinematrixget, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
536+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageaffinematrixget, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
551537
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
552538
ZEND_ARG_INFO(0, options)
553539
ZEND_END_ARG_INFO()
@@ -690,12 +676,6 @@ ZEND_FUNCTION(imageftbbox);
690676
#if defined(HAVE_GD_FREETYPE)
691677
ZEND_FUNCTION(imagefttext);
692678
#endif
693-
#if defined(HAVE_GD_FREETYPE)
694-
ZEND_FUNCTION(imagettfbbox);
695-
#endif
696-
#if defined(HAVE_GD_FREETYPE)
697-
ZEND_FUNCTION(imagettftext);
698-
#endif
699679
ZEND_FUNCTION(imagefilter);
700680
ZEND_FUNCTION(imageconvolution);
701681
ZEND_FUNCTION(imageflip);
@@ -832,10 +812,10 @@ static const zend_function_entry ext_functions[] = {
832812
ZEND_FE(imagefttext, arginfo_imagefttext)
833813
#endif
834814
#if defined(HAVE_GD_FREETYPE)
835-
ZEND_FE(imagettfbbox, arginfo_imagettfbbox)
815+
ZEND_FALIAS(imagettfbbox, imageftbbox, arginfo_imagettfbbox)
836816
#endif
837817
#if defined(HAVE_GD_FREETYPE)
838-
ZEND_FE(imagettftext, arginfo_imagettftext)
818+
ZEND_FALIAS(imagettftext, imagefttext, arginfo_imagettftext)
839819
#endif
840820
ZEND_FE(imagefilter, arginfo_imagefilter)
841821
ZEND_FE(imageconvolution, arginfo_imageconvolution)

ext/gd/tests/bug67248.phpt

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,60 @@ require __DIR__ . '/func.inc';
1111

1212
for($i=0;$i<7;$i++) {
1313
trycatch_dump(
14-
fn() => imageaffinematrixget($i)
14+
fn() => imageaffinematrixget($i, new stdClass())
1515
);
1616
}
1717
?>
18-
--EXPECT--
18+
--EXPECTF--
1919
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
2020
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
21-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
22-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
23-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
21+
22+
Notice: Object of class stdClass could not be converted to float in %s on line %d
23+
array(6) {
24+
[0]=>
25+
float(%f)
26+
[1]=>
27+
float(%f)
28+
[2]=>
29+
float(%f)
30+
[3]=>
31+
float(%f)
32+
[4]=>
33+
float(0)
34+
[5]=>
35+
float(0)
36+
}
37+
38+
Notice: Object of class stdClass could not be converted to float in %s on line %d
39+
array(6) {
40+
[0]=>
41+
float(1)
42+
[1]=>
43+
float(0)
44+
[2]=>
45+
float(%f)
46+
[3]=>
47+
float(1)
48+
[4]=>
49+
float(0)
50+
[5]=>
51+
float(0)
52+
}
53+
54+
Notice: Object of class stdClass could not be converted to float in %s on line %d
55+
array(6) {
56+
[0]=>
57+
float(1)
58+
[1]=>
59+
float(%f)
60+
[2]=>
61+
float(0)
62+
[3]=>
63+
float(1)
64+
[4]=>
65+
float(0)
66+
[5]=>
67+
float(0)
68+
}
2469
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
2570
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type

ext/phar/phar_object.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ PHP_METHOD(Phar, createDefaultStub)
928928
zend_string *stub;
929929
size_t index_len = 0, webindex_len = 0;
930930

931-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|pp", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
931+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p!p!", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
932932
RETURN_THROWS();
933933
}
934934

@@ -1833,7 +1833,7 @@ PHP_METHOD(Phar, buildFromIterator)
18331833
char *base = NULL;
18341834
struct _phar_t pass;
18351835

1836-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
1836+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s!", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
18371837
RETURN_THROWS();
18381838
}
18391839

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

2342-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
2342+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
23432343
RETURN_THROWS();
23442344
}
23452345

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

2446-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
2446+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
24472447
RETURN_THROWS();
24482448
}
24492449

@@ -2992,7 +2992,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm)
29922992
char *error, *key = NULL;
29932993
size_t key_len = 0;
29942994

2995-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &algo, &key, &key_len) != SUCCESS) {
2995+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!", &algo, &key, &key_len) != SUCCESS) {
29962996
RETURN_THROWS();
29972997
}
29982998

@@ -3155,7 +3155,7 @@ PHP_METHOD(Phar, compress)
31553155
uint32_t flags;
31563156
zend_object *ret;
31573157

3158-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &method, &ext, &ext_len) == FAILURE) {
3158+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!", &method, &ext, &ext_len) == FAILURE) {
31593159
RETURN_THROWS();
31603160
}
31613161

@@ -3221,7 +3221,7 @@ PHP_METHOD(Phar, decompress)
32213221
size_t ext_len = 0;
32223222
zend_object *ret;
32233223

3224-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ext, &ext_len) == FAILURE) {
3224+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &ext, &ext_len) == FAILURE) {
32253225
RETURN_THROWS();
32263226
}
32273227

@@ -3804,7 +3804,7 @@ PHP_METHOD(Phar, addFile)
38043804
php_stream *resource;
38053805
zval zresource;
38063806

3807-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
3807+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s!", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
38083808
RETURN_THROWS();
38093809
}
38103810

0 commit comments

Comments
 (0)