Bug #78052 [Ver]: exif_read_data chokes on strict_types for parameter 2
| From: | requinix@php.net | Date: | Thu, 23 May 2019 13:54:49 +0000 |
| Subject: | Bug #78052 [Ver]: exif_read_data chokes on strict_types for parameter 2 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220969@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78052&edit=1
ID: 78052
Updated by: requinix@php.net
Reported by: c dot schiffler at cyberspectrum dot de
Summary: exif_read_data chokes on strict_types for parameter
2
Status: Verified
Type: Bug
Package: EXIF related
Operating System: Linux
PHP Version: 7.3.5
Block user comment: N
Private report: N
New Comment:
Yeah, on second thought an empty string would be weird - PHP does null everywhere for optional
arguments, no reason to go against that here. But since someone will be in there anyways I think
adding the ZSTR_LEN check is worth it, for hypothetical code like
$sections = [];
if ($should_get_file) $sections[] = "FILE";
if ($should_get_thumbnail) $sections[] = "THUMBNAIL";
$return = exif_read_data($stream, implode(",", $sections));
Previous Comments:
------------------------------------------------------------------------
[2019-05-23 09:20:36] nikic@php.net
Agree with cmb, I think it would be better to allow an explicit null here.
------------------------------------------------------------------------
[2019-05-22 22:33:24] cmb@php.net
An alternative would be to actually allow passing NULL, i.e.
Z_PARAM_STR_EX(z_sections_needed, 1, 0)
------------------------------------------------------------------------
[2019-05-22 19:21:47] requinix@php.net
This could be a doc bug (have the argument default to "") however the source tests
specifically for null to decide if it should process the argument at all so passing an empty string
loses a bit of performance.
I think
-if (z_sections_needed) {
+if (z_sections_needed && ZSTR_LEN(z_sections_needed)) {
Then the small edit to the doc for
string $sections = ""
------------------------------------------------------------------------
[2019-05-22 19:19:56] spam2 at rhsoft dot net
param 2 is type string . period
exif_read_data ( mixed $stream [, string $sections = NULL [, bool $arrays = FALSE [, bool $thumbnail
= FALSE ]]] ) : array
------------------------------------------------------------------------
[2019-05-22 19:10:51] c dot schiffler at cyberspectrum dot de
Description:
------------
Calling exif_read_data with null as second optional parameter results in a type error.
This results in impossibility to call exif_read_data having different values for parameter 3&4
but sticking to the null default of parameter 2.
Test script:
---------------
declare(strict_types=1);
// This errors out but should not.
exif_read_data('image.jpg', null, true, false);
// This is a workaround currently in use as internal functions are not affected by strict_types per
https://bugs.php.net/bug.php?id=74750
call_user_func('exif_read_data', 'image.jpg', null, true, false);
Expected result:
----------------
Data should be extracted.
Actual result:
--------------
TypeError: exif_read_data() expects parameter 2 to be string, null given
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78052&edit=1