Skip to content

Commit 8f44ac6

Browse files
committed
Fix UNKNOWN default values in ext/mbstring and ext/gd
1 parent 69a5c56 commit 8f44ac6

File tree

9 files changed

+238
-247
lines changed

9 files changed

+238
-247
lines changed

ext/gd/gd.c

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,20 +1869,21 @@ PHP_FUNCTION(imagexbm)
18691869
zval *imgind;
18701870
char *file = NULL;
18711871
size_t file_len = 0;
1872-
zend_long foreground_color = -1;
1872+
zend_long foreground_color;
1873+
zend_bool foreground_color_is_null = 1;
18731874
gdImagePtr im;
18741875
int argc = ZEND_NUM_ARGS();
18751876
int i;
18761877
gdIOCtx *ctx = NULL;
18771878
php_stream *stream;
18781879

1879-
if (zend_parse_parameters(argc, "Op!|l", &imgind, gd_image_ce, &file, &file_len, &foreground_color) == FAILURE) {
1880+
if (zend_parse_parameters(argc, "Op!|l!", &imgind, gd_image_ce, &file, &file_len, &foreground_color, &foreground_color_is_null) == FAILURE) {
18801881
RETURN_THROWS();
18811882
}
18821883

18831884
im = php_gd_libgdimageptr_from_zval_p(imgind);
18841885

1885-
if (argc > 1 && file != NULL) {
1886+
if (file != NULL) {
18861887
stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
18871888
if (stream == NULL) {
18881889
RETURN_FALSE;
@@ -1893,10 +1894,13 @@ PHP_FUNCTION(imagexbm)
18931894
ctx = create_output_context();
18941895
}
18951896

1896-
if (argc < 3) {
1897+
if (foreground_color_is_null) {
18971898
for (i=0; i < gdImageColorsTotal(im); i++) {
1898-
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
1899+
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) {
1900+
break;
1901+
}
18991902
}
1903+
19001904
foreground_color = i;
19011905
}
19021906

@@ -1946,20 +1950,20 @@ PHP_FUNCTION(imagejpeg)
19461950
PHP_FUNCTION(imagewbmp)
19471951
{
19481952
zval *imgind;
1949-
zend_long foreground_color = -1;
1953+
zend_long foreground_color;
1954+
zend_long foreground_color_is_null = 1;
19501955
gdImagePtr im;
1951-
int argc = ZEND_NUM_ARGS();
19521956
int i;
19531957
gdIOCtx *ctx = NULL;
19541958
zval *to_zval = NULL;
19551959

1956-
if (zend_parse_parameters(argc, "O|z!l", &imgind, gd_image_ce, &to_zval, &foreground_color) == FAILURE) {
1960+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l!", &imgind, gd_image_ce, &to_zval, &foreground_color) == FAILURE) {
19571961
RETURN_THROWS();
19581962
}
19591963

19601964
im = php_gd_libgdimageptr_from_zval_p(imgind);
19611965

1962-
if (argc > 1 && to_zval != NULL) {
1966+
if (to_zval != NULL) {
19631967
ctx = create_stream_context_from_zval(to_zval);
19641968
if (!ctx) {
19651969
RETURN_FALSE;
@@ -1968,10 +1972,11 @@ PHP_FUNCTION(imagewbmp)
19681972
ctx = create_output_context();
19691973
}
19701974

1971-
if (argc < 3) {
1975+
if (foreground_color_is_null) {
19721976
for (i=0; i < gdImageColorsTotal(im); i++) {
1973-
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i))
1977+
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) {
19741978
break;
1979+
}
19751980
}
19761981

19771982
foreground_color = i;
@@ -2006,17 +2011,16 @@ PHP_FUNCTION(imagebmp)
20062011
zval *imgind;
20072012
zend_bool compressed = 1;
20082013
gdImagePtr im;
2009-
int argc = ZEND_NUM_ARGS();
20102014
gdIOCtx *ctx = NULL;
20112015
zval *to_zval = NULL;
20122016

2013-
if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
2017+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) {
20142018
RETURN_THROWS();
20152019
}
20162020

20172021
im = php_gd_libgdimageptr_from_zval_p(imgind);
20182022

2019-
if (argc > 1 && to_zval != NULL) {
2023+
if (to_zval != NULL) {
20202024
ctx = create_stream_context_from_zval(to_zval);
20212025
if (!ctx) {
20222026
RETURN_FALSE;
@@ -2555,16 +2559,16 @@ PHP_FUNCTION(imagecolortransparent)
25552559
{
25562560
zval *IM;
25572561
zend_long COL = 0;
2562+
zend_bool COL_IS_NULL = 1;
25582563
gdImagePtr im;
2559-
int argc = ZEND_NUM_ARGS();
25602564

2561-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &COL) == FAILURE) {
2565+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &COL, &COL_IS_NULL) == FAILURE) {
25622566
RETURN_THROWS();
25632567
}
25642568

25652569
im = php_gd_libgdimageptr_from_zval_p(IM);
25662570

2567-
if (argc > 1) {
2571+
if (!COL_IS_NULL) {
25682572
gdImageColorTransparent(im, COL);
25692573
}
25702574

@@ -2576,17 +2580,17 @@ PHP_FUNCTION(imagecolortransparent)
25762580
PHP_FUNCTION(imageinterlace)
25772581
{
25782582
zval *IM;
2579-
int argc = ZEND_NUM_ARGS();
25802583
zend_long INT = 0;
2584+
zend_bool INT_IS_NULL = 1;
25812585
gdImagePtr im;
25822586

2583-
if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &INT) == FAILURE) {
2587+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &IM, gd_image_ce, &INT, &INT_IS_NULL) == FAILURE) {
25842588
RETURN_THROWS();
25852589
}
25862590

25872591
im = php_gd_libgdimageptr_from_zval_p(IM);
25882592

2589-
if (argc > 1) {
2593+
if (!INT_IS_NULL) {
25902594
gdImageInterlace(im, INT);
25912595
}
25922596

@@ -2603,15 +2607,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
26032607
{
26042608
zval *IM, *POINTS;
26052609
zend_long NPOINTS, COL;
2610+
zend_bool COL_IS_NULL = 1;
26062611
zval *var = NULL;
26072612
gdImagePtr im;
26082613
gdPointPtr points;
26092614
int npoints, col, nelem, i;
26102615

2611-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL) == FAILURE) {
2616+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oal|l!", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL, &COL_IS_NULL) == FAILURE) {
26122617
RETURN_THROWS();
26132618
}
2614-
if (ZEND_NUM_ARGS() == 3) {
2619+
if (COL_IS_NULL) {
26152620
COL = NPOINTS;
26162621
NPOINTS = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
26172622
if (NPOINTS % 2 != 0) {
@@ -3733,7 +3738,7 @@ PHP_FUNCTION(imageaffine)
37333738
int i, nelems;
37343739
zval *zval_affine_elem = NULL;
37353740

3736-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
3741+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a!", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) {
37373742
RETURN_THROWS();
37383743
}
37393744

@@ -3856,7 +3861,7 @@ PHP_FUNCTION(imageaffinematrixget)
38563861
double angle;
38573862

38583863
if (!options) {
3859-
zend_argument_type_error(2, "must be of type int|double when using rotate or shear");
3864+
zend_argument_type_error(2, "must be of type int|float when using rotate or shear");
38603865
RETURN_THROWS();
38613866
}
38623867

@@ -4003,26 +4008,29 @@ PHP_FUNCTION(imageresolution)
40034008
{
40044009
zval *IM;
40054010
gdImagePtr im;
4006-
zend_long res_x = GD_RESOLUTION, res_y = GD_RESOLUTION;
4011+
zend_long res_x, res_y;
4012+
zend_bool res_x_is_null = 1, res_y_is_null = 1;
40074013

4008-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &IM, gd_image_ce, &res_x, &res_y) == FAILURE) {
4014+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!l!", &IM, gd_image_ce, &res_x, &res_x_is_null, &res_y, &res_y_is_null) == FAILURE) {
40094015
RETURN_THROWS();
40104016
}
40114017

40124018
im = php_gd_libgdimageptr_from_zval_p(IM);
40134019

4014-
switch (ZEND_NUM_ARGS()) {
4015-
case 3:
4016-
gdImageSetResolution(im, res_x, res_y);
4017-
RETURN_TRUE;
4018-
case 2:
4019-
gdImageSetResolution(im, res_x, res_x);
4020-
RETURN_TRUE;
4021-
default:
4022-
array_init(return_value);
4023-
add_next_index_long(return_value, gdImageResolutionX(im));
4024-
add_next_index_long(return_value, gdImageResolutionY(im));
4020+
if (!res_x_is_null && !res_y_is_null) {
4021+
gdImageSetResolution(im, res_x, res_y);
4022+
RETURN_TRUE;
4023+
} else if (!res_x_is_null && res_y_is_null) {
4024+
gdImageSetResolution(im, res_x, res_x);
4025+
RETURN_TRUE;
4026+
} else if (res_x_is_null && !res_y_is_null) {
4027+
gdImageSetResolution(im, res_y, res_y);
4028+
RETURN_TRUE;
40254029
}
4030+
4031+
array_init(return_value);
4032+
add_next_index_long(return_value, gdImageResolutionX(im));
4033+
add_next_index_long(return_value, gdImageResolutionY(im));
40264034
}
40274035
/* }}} */
40284036

@@ -4156,7 +4164,11 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41564164
gdIOCtx *ctx = NULL;
41574165
zval *to_zval = NULL;
41584166

4159-
if (image_type == PHP_GDIMG_TYPE_PNG) {
4167+
if (image_type == PHP_GDIMG_TYPE_GIF) {
4168+
if (zend_parse_parameters(argc, "O|z", &imgind, gd_image_ce, &to_zval) == FAILURE) {
4169+
RETURN_THROWS();
4170+
}
4171+
} else if (image_type == PHP_GDIMG_TYPE_PNG) {
41604172
if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) {
41614173
RETURN_THROWS();
41624174
}
@@ -4168,7 +4180,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41684180

41694181
im = php_gd_libgdimageptr_from_zval_p(imgind);
41704182

4171-
if (argc > 1 && to_zval != NULL) {
4183+
if (to_zval != NULL) {
41724184
ctx = create_stream_context_from_zval(to_zval);
41734185
if (!ctx) {
41744186
RETURN_FALSE;
@@ -4190,16 +4202,6 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41904202
case PHP_GDIMG_TYPE_PNG:
41914203
(*func_p)(im, ctx, (int) quality, (int) basefilter);
41924204
break;
4193-
case PHP_GDIMG_TYPE_WBM:
4194-
if (argc < 3) {
4195-
for (i=0; i < gdImageColorsTotal(im); i++) {
4196-
if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
4197-
}
4198-
quality = (int) i;
4199-
}
4200-
4201-
(*func_p)(im, (int) quality, ctx);
4202-
break;
42034205
case PHP_GDIMG_TYPE_GIF:
42044206
(*func_p)(im, ctx);
42054207
break;

ext/gd/gd.stub.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function gd_info(): array {}
1010

1111
function imageloadfont(string $filename): int|false {}
1212

13-
function imagesetstyle($im, array $styles): bool {}
13+
function imagesetstyle(GdImage $im, array $styles): bool {}
1414

1515
function imagecreatetruecolor(int $x_size, int $y_size): GdImage|false {}
1616

@@ -20,7 +20,7 @@ function imagetruecolortopalette(GdImage $im, bool $ditherFlag, int $colorWanted
2020

2121
function imagepalettetotruecolor(GdImage $im): bool {}
2222

23-
function imagecolormatch($im1, $im2): bool {}
23+
function imagecolormatch(GdImage $im1, GdImage $im2): bool {}
2424

2525
function imagesetthickness(GdImage $im, int $thickness): bool {}
2626

@@ -54,9 +54,9 @@ function imagegrabscreen(): GdImage|false {}
5454

5555
function imagerotate(GdImage $im, float $angle, int $bgdcolor, int $ignoretransparent = 0): GdImage|false {}
5656

57-
function imagesettile(GdImage $im, $tile): bool {}
57+
function imagesettile(GdImage $im, GdImage $tile): bool {}
5858

59-
function imagesetbrush(GdImage $im, $brush): bool {}
59+
function imagesetbrush(GdImage $im, GdImage $brush): bool {}
6060

6161
function imagecreate(int $x_size, int $y_size): GdImage|false {}
6262

@@ -100,30 +100,36 @@ function imagecreatefrombmp(string $filename): GdImage|false {}
100100
function imagecreatefromtga(string $filename): GdImage|false {}
101101
#endif
102102

103-
function imagexbm(GdImage $im, ?string $filename, int $foreground = UNKNOWN): bool {}
103+
function imagexbm(GdImage $im, ?string $filename, ?int $foreground = null): bool {}
104104

105+
/** @param resource|string|null $to */
105106
function imagegif(GdImage $im, $to = null): bool {}
106107

107108
#ifdef HAVE_GD_PNG
108-
function imagepng(GdImage $im, $to = null, int $quality = UNKNOWN, int $filters = UNKNOWN): bool {}
109+
/** @param resource|string|null $to */
110+
function imagepng(GdImage $im, $to = null, int $quality = -1, int $filters = -1): bool {}
109111
#endif
110112

111113
#ifdef HAVE_GD_WEBP
112-
function imagewebp(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
114+
/** @param resource|string|null $to */
115+
function imagewebp(GdImage $im, $to = null, int $quality = -1): bool {}
113116
#endif
114117

115118
#ifdef HAVE_GD_JPG
116-
function imagejpeg(GdImage $im, $to = null, int $quality = UNKNOWN): bool {}
119+
/** @param resource|string|null $to */
120+
function imagejpeg(GdImage $im, $to = null, int $quality = -1): bool {}
117121
#endif
118122

119-
function imagewbmp(GdImage $im, $to = null, int $foreground = UNKNOWN): bool {}
123+
/** @param resource|string|null $to */
124+
function imagewbmp(GdImage $im, $to = null, ?int $foreground = null): bool {}
120125

121126
function imagegd(GdImage $im, $to = UNKNOWN): bool {}
122127

123128
function imagegd2(GdImage $im, $to = UNKNOWN, int $chunk_size = UNKNOWN, int $type = UNKNOWN): bool {}
124129

125130
#ifdef HAVE_GD_BMP
126-
function imagebmp(GdImage $im, $to = null, int $compressed = 1): bool {}
131+
/** @param resource|string|null $to */
132+
function imagebmp(GdImage $im, $to = null, bool $compressed = true): bool {}
127133
#endif
128134

129135
function imagedestroy(GdImage $im): bool {}
@@ -170,15 +176,15 @@ function imagefill(GdImage $im, int $x, int $y, int $col): bool {}
170176

171177
function imagecolorstotal(GdImage $im): int {}
172178

173-
function imagecolortransparent(GdImage $im, int $col = UNKNOWN): ?int {}
179+
function imagecolortransparent(GdImage $im, ?int $col = null): ?int {}
174180

175-
function imageinterlace(GdImage $im, int $interlace = UNKNOWN): ?int {}
181+
function imageinterlace(GdImage $im, ?int $interlace = null): ?int {}
176182

177-
function imagepolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
183+
function imagepolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
178184

179-
function imageopenpolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
185+
function imageopenpolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
180186

181-
function imagefilledpolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}
187+
function imagefilledpolygon(GdImage $im, array $points, int $num_points_or_col, ?int $col = null): bool {}
182188

183189
function imagefontwidth(int $font): int {}
184190

@@ -230,10 +236,11 @@ function imagecrop(GdImage $im, array $rect): GdImage|false {}
230236

231237
function imagecropauto(GdImage $im, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1): GdImage|false {}
232238

233-
function imagescale(GdImage $im, int $new_width, int $new_height = UNKNOWN, int $mode = IMG_BILINEAR_FIXED): GdImage|false {}
239+
function imagescale(GdImage $im, int $new_width, int $new_height = -1, int $mode = IMG_BILINEAR_FIXED): GdImage|false {}
234240

235-
function imageaffine(GdImage $im, array $affine, array $clip = UNKNOWN): GdImage|false {}
241+
function imageaffine(GdImage $im, array $affine, ?array $clip = null): GdImage|false {}
236242

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

239246
function imageaffinematrixconcat(array $m1, array $m2): array|false {}
@@ -242,4 +249,4 @@ function imagegetinterpolation(GdImage $im): int {}
242249

243250
function imagesetinterpolation(GdImage $im, int $method = IMG_BILINEAR_FIXED): bool {}
244251

245-
function imageresolution(GdImage $im, int $res_x = UNKNOWN, int $res_y = UNKNOWN): array|bool {}
252+
function imageresolution(GdImage $im, ?int $res_x = null, ?int $res_y = null): array|bool {}

0 commit comments

Comments
 (0)