]> granicus.if.org Git - php/commitdiff
Make imagegd $file parameter nullable
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 9 Feb 2021 14:15:20 +0000 (15:15 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 9 Feb 2021 14:15:20 +0000 (15:15 +0100)
It is explicitly documented to be nullable, and this matches other
functions like imagepng. It is also documented to accept a stream,
which it currently does not...

ext/gd/gd.c
ext/gd/gd.stub.php
ext/gd/gd_arginfo.h

index 7a50fb423ede019dad472a2e148440f166e1ec2e..c1329d13cfd4909b7712bc5e41aeac87f8e9f68a 100644 (file)
@@ -1778,7 +1778,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
        char *file = NULL;
        zend_long quality = 0, type = 0;
        gdImagePtr im;
-       char *fn = NULL;
        FILE *fp;
        size_t file_len = 0;
        int argc = ZEND_NUM_ARGS();
@@ -1786,28 +1785,25 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
 
        /* The quality parameter for gd2 stands for chunk size */
 
-       if (zend_parse_parameters(argc, "O|pll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
+       if (zend_parse_parameters(argc, "O|p!ll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
                RETURN_THROWS();
        }
 
        im = php_gd_libgdimageptr_from_zval_p(imgind);
 
-       if (argc > 1) {
-               fn = file;
-               if (argc >= 3) {
-                       q = quality;
-                       if (argc == 4) {
-                               t = type;
-                       }
+       if (argc >= 3) {
+               q = quality;
+               if (argc == 4) {
+                       t = type;
                }
        }
 
-       if (argc >= 2 && file_len) {
-               PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
+       if (file_len) {
+               PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
 
-               fp = VCWD_FOPEN(fn, "wb");
+               fp = VCWD_FOPEN(file, "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", file);
                        RETURN_FALSE;
                }
 
index fe0d5658eef70998d4fbd41d902f754609cf7508..27290ff4aba61d4f1165e51c57c398a868928609 100644 (file)
@@ -124,9 +124,9 @@ function imagejpeg(GdImage $image, $file = null, int $quality = -1): bool {}
 /** @param resource|string|null $file */
 function imagewbmp(GdImage $image, $file = null, ?int $foreground_color = null): bool {}
 
-function imagegd(GdImage $image, string $file = UNKNOWN): bool {}
+function imagegd(GdImage $image, ?string $file = null): bool {}
 
-function imagegd2(GdImage $image, string $file = UNKNOWN, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
+function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
 
 #ifdef HAVE_GD_BMP
 /** @param resource|string|null $file */
index 4d59767b4eb93cfa803b993f9915aaa971fc56a1..4baeccace3583d152b418880f4bf82e64dd0df93 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 59256d0de105f1a2f5d5fc1e20f8090031b42a76 */
+ * Stub hash: 63898b501cc3ae38585fe0c6f70a9f7865fbee4d */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
 ZEND_END_ARG_INFO()
@@ -238,12 +238,12 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
-       ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd2, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
-       ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
        ZEND_ARG_TYPE_INFO(0, chunk_size, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
 ZEND_END_ARG_INFO()