php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66443 Corrupt EXIF header: maximum directory nesting level reached for some cameras.
Submitted: 2014-01-08 19:42 UTC Modified: 2017-10-24 01:04 UTC
Votes:39
Avg. Score:4.4 ± 0.7
Reproduced:37 of 37 (100.0%)
Same Version:6 (16.2%)
Same OS:24 (64.9%)
From: ianbeckett dot 0405 at gmail dot com Assigned: kalle (profile)
Status: Closed Package: EXIF related
PHP Version: 5.5.7 OS: Linux
Private report: No CVE-ID: None
 [2014-01-08 19:42 UTC] ianbeckett dot 0405 at gmail dot com
Description:
------------
EXIF data from certain cameras is not read correctly by exif_read_data(), it fails part way through with the error "Corrupt EXIF header: maximum directory nesting level reached".

My camera is a Fujifilm F770EXR and the two links below are additional reports of the same problem with Fujifilm cameras. I don't know if any other makes are affected.

http://stackoverflow.com/questions/11584238/php-corrupt-exif-data-error-with-fulifilm-photos

http://stackoverflow.com/questions/10075066/issues-extracting-exif-data-for-exif-2-3-using-php-version-5-2-9

I think the problem is due to the amount of extra tags Fujifilm include, causing the code in exif.c to think the header is corrupt before it finishes reading it all.

I think it can be fixed by increasing the value of MAX_IFD_NESTING_LEVEL defined in ext/exif/exif.c. I used a value of 200 and it appears to have resolved the problem on my installation.





Patches

Increase-MAX_IFD_NESTING_LEVEL (last revision 2014-06-15 09:06 UTC) by ianbeckett dot 0405 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-22 10:15 UTC] hello at wentsch dot me
Thanks for your patch, took me a while to figure out it's a problem with the EXIF produced by my camera, which is a Fujifilm X10 fyi.
 [2014-10-06 11:45 UTC] deemoos at live dot nl
Why is there no fix included in new PHP versions?
 [2014-10-06 19:57 UTC] ianbeckett dot 0405 at gmail dot com
I don't know why a fix is not included, it seems to be a very straightforward change with no side-effects.

I have been applying the fix I described originally every time I upgrade php and it works very well.
 [2016-08-03 10:00 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2016-08-03 10:00 UTC] kalle@php.net
Please try using this snapshot:

  http://snaps.php.net/php-trunk-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I just committed a fix for adding support for Panasonic formats, which involved increasing this limit to 150, can you confirm this still works with that, or do you need it to be 200 for the Fujifilm format to work?
 [2016-08-03 10:01 UTC] kalle@php.net
-Assigned To: +Assigned To: kalle
 [2016-08-05 05:53 UTC] kalle@php.net
-Status: Feedback +Status: Closed
 [2016-08-05 05:53 UTC] kalle@php.net
Gonna mark this as fixed, ping me if 150 is too short so I can look into it, thanks!
 [2017-10-24 00:02 UTC] Heikki dot Vesanto at gmail dot com
I'm having this issue on php 7.2.

php -v
PHP 7.2.0RC4 (cli) (built: Oct 22 2017 13:39:08) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.2.0RC4, Copyright (c) 1999-2017, by Zend Technologies

Error I get:

PHP Warning:  exif_read_data(12_Adventure_Duck.jpg): corrupt EXIF header: maximum directory nesting level reached in /var/www/maps.gisforthought.com/html/getphotos.php on line 16

You can find the image at: https://maps.gisforthought.com/Photos/12_Adventure_Duck.jpg

EXIF as shown by the Linux exif terminal command:

EXIF tags in '12_Adventure_Duck.jpg' ('Intel' byte order):
--------------------+----------------------------------------------------------
Tag                 |Value
--------------------+----------------------------------------------------------
Manufacturer        |Panasonic
Model               |DMC-TZ40
X-Resolution        |180
Y-Resolution        |180
Resolution Unit     |Inch
Software            |Ver.1.2
Date and Time       |2014:05:26 05:42:32
Artist              |Picasa
YCbCr Positioning   |Co-sited
PRINT Image Matching|208 bytes undefined data
Compression         |JPEG compression
X-Resolution        |72
Y-Resolution        |72
Resolution Unit     |Inch
Exposure Time       |1/800 sec.
F-Number            |f/3.3
Exposure Program    |Normal program
ISO Speed Ratings   |100
Exif Version        |Exif Version 2.3
Date and Time (Origi|2014:05:26 05:42:32
Date and Time (Digit|2014:05:26 05:42:32
Components Configura|Y Cb Cr -
Compressed Bits per | 4
Exposure Bias       |0.00 EV
Maximum Aperture Val|3.45 EV (f/3.3)
Metering Mode       |Center-weighted average
Light Source        |Unknown
Flash               |Flash did not fire, compulsory flash mode
Focal Length        |4.3 mm
Maker Note          |3596 bytes undefined data
FlashPixVersion     |FlashPix Version 1.0
Color Space         |sRGB
Pixel X Dimension   |1131
Pixel Y Dimension   |848
Sensing Method      |One-chip color area sensor
File Source         |DSC
Scene Type          |Directly photographed
Custom Rendered     |Normal process
Exposure Mode       |Auto exposure
White Balance       |Auto white balance
Digital Zoom Ratio  |0.0
Focal Length in 35mm|24
Scene Capture Type  |Standard
Gain Control        |Normal
Contrast            |Normal
Saturation          |Normal
Sharpness           |Normal
Image Unique ID     |1b5003f64a45bef4946ef7a95f8d18a6
GPS Tag Version     |2.2.0.0
North or South Latit|N
Latitude            |40, 27, 15.812
East or West Longitu|E
Longitude           |116, 32, 10.7166
Altitude Reference  |Sea level
Altitude            |971.380
GPS Time (Atomic Clo|04:42:32.00
GPS Receiver Status |V
GPS Measurement Mode|2
Measurement Precisio|0.0
GPS Image Direction |M
GPS Image Direction |135
Geodetic Survey Data|WGS-84
Name of GPS Processi|14 bytes undefined data
Name of GPS Area    |266 bytes undefined data
GPS Date            |2014:05:26
Interoperability Ind|R98
Interoperability Ver|0100
RelatedImageWidth   |4896
RelatedImageLength  |3672
--------------------+----------------------------------------------------------
EXIF data contains a thumbnail (5865 bytes).
 [2017-10-24 01:04 UTC] kalle@php.net
@Heikki can you please open a new report and assign it to me and I will take a look? Thanks
 [2017-10-24 11:17 UTC] Heikki dot Vesanto at gmail dot com
Hi kalle, sorry I was not able to assign the bug to you, but I have created it at:
https://bugs.php.net/bug.php?id=75424
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC