Skip to content

Commit 8694eb1

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix bug #75785 by attempt switching endianness on Maker's Note
2 parents e25aab6 + 5c55086 commit 8694eb1

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

ext/exif/exif.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef unsigned char uchar;
6262

6363
#define EFREE_IF(ptr) if (ptr) efree(ptr)
6464

65-
#define MAX_IFD_NESTING_LEVEL 150
65+
#define MAX_IFD_NESTING_LEVEL 200
6666

6767
/* {{{ PHP_MINFO_FUNCTION */
6868
PHP_MINFO_FUNCTION(exif)
@@ -3185,14 +3185,12 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
31853185

31863186
NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
31873187

3188-
switch (maker_note->offset_mode) {
3189-
case MN_OFFSET_MAKER:
3190-
exif_offset_info_init(&new_info, value_ptr, value_ptr, value_len);
3191-
info = &new_info;
3192-
break;
3193-
default:
3194-
case MN_OFFSET_NORMAL:
3195-
break;
3188+
/* It can be that motorola_intel is wrongly mapped, let's try inverting it */
3189+
if ((2+NumDirEntries*12) > value_len) {
3190+
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Potentially invalid endianess, trying again with different endianness before imminent failure.");
3191+
3192+
ImageInfo->motorola_intel = ImageInfo->motorola_intel == 0 ? 1 : 0;
3193+
NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
31963194
}
31973195

31983196
if ((2+NumDirEntries*12) > value_len) {
@@ -3204,6 +3202,16 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
32043202
return false;
32053203
}
32063204

3205+
switch (maker_note->offset_mode) {
3206+
case MN_OFFSET_MAKER:
3207+
exif_offset_info_init(&new_info, value_ptr, value_ptr, value_len);
3208+
info = &new_info;
3209+
break;
3210+
default:
3211+
case MN_OFFSET_NORMAL:
3212+
break;
3213+
}
3214+
32073215
for (de=0;de<NumDirEntries;de++) {
32083216
size_t offset = 2 + 12 * de;
32093217
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)