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: 2021-03-07 04:22 UTC
Votes:6
Avg. Score:4.2 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:3 (50.0%)
From: php at lho dot io Assigned: cmb (profile)
Status: No Feedback Package: EXIF related
PHP Version: 7.4.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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>
 [2021-02-26 12:19 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-02-26 12:19 UTC] cmb@php.net
Is this resolved as of PHP 7.3.23 and 7.4.11, respectively, or is
there still an issue?
 [2021-03-07 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC