Skip to content

Commit 5c55086

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #75785 by attempt switching endianness on Maker's Note
2 parents 4609ded + 2fa4ca9 commit 5c55086

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
. Fixed bug #48585 (com_load_typelib holds reference, fails on second call).
1919
(cmb)
2020

21+
- Exif:
22+
. Fixed bug #75785 (Many errors from exif_read_data).
23+
(Níckolas Daniel da Silva)
24+
2125
- Gettext:
2226
. Fixed bug #70574 (Tests fail due to relying on Linux fallback behavior for
2327
gettext()). (Florian Engelhardt)

ext/exif/exif.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef unsigned char uchar;
6464

6565
#define EFREE_IF(ptr) if (ptr) efree(ptr)
6666

67-
#define MAX_IFD_NESTING_LEVEL 150
67+
#define MAX_IFD_NESTING_LEVEL 200
6868

6969
/* {{{ arginfo */
7070
ZEND_BEGIN_ARG_INFO(arginfo_exif_tagname, 0)
@@ -3210,6 +3210,23 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
32103210

32113211
NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
32123212

3213+
/* It can be that motorola_intel is wrongly mapped, let's try inverting it */
3214+
if ((2+NumDirEntries*12) > value_len) {
3215+
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Potentially invalid endianess, trying again with different endianness before imminent failure.");
3216+
3217+
ImageInfo->motorola_intel = ImageInfo->motorola_intel == 0 ? 1 : 0;
3218+
NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
3219+
}
3220+
3221+
if ((2+NumDirEntries*12) > value_len) {
3222+
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: 2 + 0x%04X*12 = 0x%04X > 0x%04X", NumDirEntries, 2+NumDirEntries*12, value_len);
3223+
return FALSE;
3224+
}
3225+
if ((dir_start - value_ptr) > value_len - (2+NumDirEntries*12)) {
3226+
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: 0x%04X > 0x%04X", (dir_start - value_ptr) + (2+NumDirEntries*12), value_len);
3227+
return FALSE;
3228+
}
3229+
32133230
switch (maker_note->offset_mode) {
32143231
case MN_OFFSET_MAKER:
32153232
offset_base = value_ptr;
@@ -3240,15 +3257,6 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
32403257
break;
32413258
}
32423259

3243-
if ((2+NumDirEntries*12) > value_len) {
3244-
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: 2 + 0x%04X*12 = 0x%04X > 0x%04X", NumDirEntries, 2+NumDirEntries*12, value_len);
3245-
return FALSE;
3246-
}
3247-
if ((dir_start - value_ptr) > value_len - (2+NumDirEntries*12)) {
3248-
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: 0x%04X > 0x%04X", (dir_start - value_ptr) + (2+NumDirEntries*12), value_len);
3249-
return FALSE;
3250-
}
3251-
32523260
for (de=0;de<NumDirEntries;de++) {
32533261
size_t offset = 2 + 12 * de;
32543262
if (!exif_process_IFD_TAG(ImageInfo, dir_start + offset,

ext/exif/tests/bug75785/P1000506.JPG

34.7 KB
Loading

ext/exif/tests/bug75785/bug75785.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #75785 fix corrupt EXIF header issues; Related to mixed endianness. (Thank you @Richard Matzinger for providing the test photo)
3+
--SKIPIF--
4+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
5+
--FILE--
6+
<?php
7+
$mixedEndiannessFile = dirname(__FILE__).'/P1000506.JPG';
8+
$tags = exif_read_data($mixedEndiannessFile, 'EXIF', true, false);
9+
10+
echo $tags['GPS']['GPSLatitude'][0] . PHP_EOL;
11+
echo $tags['GPS']['GPSLongitude'][0] . PHP_EOL;
12+
?>
13+
===DONE===
14+
--EXPECTF--
15+
38/1
16+
122/1
17+
===DONE===

0 commit comments

Comments
 (0)