php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79907 exif_read_data() corrupt EXIF header: maximum directory nesting level reached
Submitted: 2020-07-28 12:29 UTC Modified: 2020-08-12 08:16 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: php at lho dot io Assigned:
Status: Open Package: EXIF related
PHP Version: 7.4.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at lho dot io
New email:
PHP Version: OS:

 

 [2020-07-28 12:29 UTC] php at lho dot io
Description:
------------
Might be the same problem as in https://bugs.php.net/bug.php?id=78083, I'm no EXIF expert. In that case, let the reference photo be another datapoint.

When reading exif data from an image (which works fine in exiftool), I get the error:
PHP Warning:  exif_read_data(DSCF1362.jpg): corrupt EXIF header: maximum directory nesting level reached in /home/leo/Downloads/test/script.php on line 2

Geodata is missing in the result. 

Most images taken with the same camera (Fuji X-T30) and edited with darktable work, but I have 8 images where this error happens. Upon request, I can provide additional images. Link to the image causing this specific error: https://gofile.io/d/A42LUr

Test script:
---------------
<?php
$exif = exif_read_data('DSCF1362.jpg', 0, true);
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: ";
        print_r($val);
        echo "<br />\n";
    }
}
?>

Expected result:
----------------
Should read all EXIF data correctly

Actual result:
--------------
Error message and missing data

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-09 15:10 UTC] lookingdown at mail dot com
ext/exif/exif.c
line 69
#define MAX_IFD_NESTING_LEVEL 150

changing this to 

#define MAX_IFD_NESTING_LEVEL 300

Should cover most EXIF value scenarios, f.ex. Panasonic GH4 with added GPS info have 244 entries.

After value change of MAX_IFD_NESTING_LEVEL to desired value f.ex. 300 in exif.c  recompile module and replace exif.so in extension dir of PHP installation. 

Tested with 7.3 from github src repo. Seems to do the trick, the problem have nothing to do with inherent limitations of PHP as suggested elsewhere, just this restriction/limitation hardcoded in extension exif.
 [2020-08-12 08:01 UTC] nikic@php.net
Looks like ifd_nesting_level only ever gets incremented, so MAX_IFD_NESTING_LEVEL is not really a "nesting level" but rather MAX_NUMBER_OF_IFD_TAGS.

I suspect that is not what was intended.
 [2020-08-12 08:13 UTC] nikic@php.net
The following pull request has been associated:

Patch Name: Make MAX_IFD_NESTING_LEVEL an actual nesting level
On GitHub:  https://github.com/php/php-src/pull/5976
Patch:      https://github.com/php/php-src/pull/5976.patch
 [2020-08-12 08:15 UTC] php at lho dot io
I can confirm increasing the nesting limit works for my files. Is it possible for this limit to get raised upstream? I'm guessing that in the future more cameras are only going to add more metadata to the pictures and it'd great for user experience if it worked out of the box.
 [2020-08-12 08:16 UTC] cmb@php.net
> I suspect that is not what was intended.

Probably not, see bug #31986, and also bug #28451; the fix for the
latter introduced the constant with value 5[1].

[1] <http://git.php.net/?p=php-src.git;a=commit;h=ecb9f8668db5cc05734aa77b406028ca38ae2284>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 06:01:24 2020 UTC