Skip to content

Commit 550aee0

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Properly check imagegd() signature Make imagegd $file parameter nullable
2 parents 9d54609 + 57cb01a commit 550aee0

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

ext/gd/gd.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,36 +1820,42 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
18201820
char *file = NULL;
18211821
zend_long quality = 0, type = 0;
18221822
gdImagePtr im;
1823-
char *fn = NULL;
18241823
FILE *fp;
18251824
size_t file_len = 0;
18261825
int argc = ZEND_NUM_ARGS();
18271826
int q = -1, t = 1;
18281827

18291828
/* The quality parameter for gd2 stands for chunk size */
18301829

1831-
if (zend_parse_parameters(argc, "O|pll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
1832-
RETURN_THROWS();
1830+
switch (image_type) {
1831+
case PHP_GDIMG_TYPE_GD:
1832+
if (zend_parse_parameters(argc, "O|p!", &imgind, gd_image_ce, &file, &file_len) == FAILURE) {
1833+
RETURN_THROWS();
1834+
}
1835+
break;
1836+
case PHP_GDIMG_TYPE_GD2:
1837+
if (zend_parse_parameters(argc, "O|p!ll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
1838+
RETURN_THROWS();
1839+
}
1840+
break;
1841+
EMPTY_SWITCH_DEFAULT_CASE()
18331842
}
18341843

18351844
im = php_gd_libgdimageptr_from_zval_p(imgind);
18361845

1837-
if (argc > 1) {
1838-
fn = file;
1839-
if (argc >= 3) {
1840-
q = quality;
1841-
if (argc == 4) {
1842-
t = type;
1843-
}
1846+
if (argc >= 3) {
1847+
q = quality;
1848+
if (argc == 4) {
1849+
t = type;
18441850
}
18451851
}
18461852

1847-
if (argc >= 2 && file_len) {
1848-
PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
1853+
if (file_len) {
1854+
PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
18491855

1850-
fp = VCWD_FOPEN(fn, "wb");
1856+
fp = VCWD_FOPEN(file, "wb");
18511857
if (!fp) {
1852-
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", fn);
1858+
php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", file);
18531859
RETURN_FALSE;
18541860
}
18551861

ext/gd/gd.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ function imagejpeg(GdImage $image, $file = null, int $quality = -1): bool {}
125125
/** @param resource|string|null $file */
126126
function imagewbmp(GdImage $image, $file = null, ?int $foreground_color = null): bool {}
127127

128-
function imagegd(GdImage $image, string $file = UNKNOWN): bool {}
128+
function imagegd(GdImage $image, ?string $file = null): bool {}
129129

130-
function imagegd2(GdImage $image, string $file = UNKNOWN, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
130+
function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
131131

132132
#ifdef HAVE_GD_BMP
133133
/** @param resource|string|null $file */

ext/gd/gd_arginfo.h

Lines changed: 3 additions & 3 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: e5688b77ea52f6df10e3335594d9fc1956c10c34 */
2+
* Stub hash: 884e30d9f263c5873d15cec9c2d2f1fef5b75fe6 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -238,12 +238,12 @@ ZEND_END_ARG_INFO()
238238

239239
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd, 0, 1, _IS_BOOL, 0)
240240
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
241-
ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
241+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
242242
ZEND_END_ARG_INFO()
243243

244244
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd2, 0, 1, _IS_BOOL, 0)
245245
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
246-
ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
246+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
247247
ZEND_ARG_TYPE_INFO(0, chunk_size, IS_LONG, 0)
248248
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
249249
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)