php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78052 exif_read_data chokes on strict_types for parameter 2
Submitted: 2019-05-22 19:10 UTC Modified: 2019-09-12 16:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: c dot schiffler at cyberspectrum dot de Assigned: kalle (profile)
Status: Assigned Package: EXIF related
PHP Version: 7.3.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
19 + 15 = ?
Subscribe to this entry?

 
 [2019-05-22 19:10 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-22 19:19 UTC] 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:21 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2019-05-22 19:21 UTC] 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 22:33 UTC] 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-23 09:20 UTC] nikic@php.net
Agree with cmb, I think it would be better to allow an explicit null here.
 [2019-05-23 13:54 UTC] requinix@php.net
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));
 [2019-09-12 16:16 UTC] kalle@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: kalle
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 18:01:24 2019 UTC