From 2fa4ca95db262267aa6bd46c5e2f74aa42542fc3 Mon Sep 17 00:00:00 2001 From: Nawarian Date: Sun, 12 Jul 2020 21:53:52 +0200 Subject: [PATCH] Fix bug #75785 by attempt switching endianness on Maker's Note Different manufacturer models may come with a different endianness (motorola/intel) format. In order to avoid a big refactor and a gigantic lookup table, this commit simply attempts to switch the endianness and proceed when values are acceptable. Closes GH-5849. --- NEWS | 4 ++++ ext/exif/exif.c | 28 +++++++++++++++++--------- ext/exif/tests/bug75785/P1000506.JPG | Bin 0 -> 35516 bytes ext/exif/tests/bug75785/bug75785.phpt | 17 ++++++++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 ext/exif/tests/bug75785/P1000506.JPG create mode 100644 ext/exif/tests/bug75785/bug75785.phpt diff --git a/NEWS b/NEWS index 6b85632037..d79a06a2bb 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,10 @@ PHP NEWS . Fixed bug #48585 (com_load_typelib holds reference, fails on second call). (cmb) +- Exif: + . Fixed bug #75785 (Many errors from exif_read_data). + (Níckolas Daniel da Silva) + - Gettext: . Fixed bug #70574 (Tests fail due to relying on Linux fallback behavior for gettext()). (Florian Engelhardt) diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 4cb36c534b..5e4c23f4e6 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -66,7 +66,7 @@ typedef unsigned char uchar; #define EFREE_IF(ptr) if (ptr) efree(ptr) -#define MAX_IFD_NESTING_LEVEL 150 +#define MAX_IFD_NESTING_LEVEL 200 /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO(arginfo_exif_tagname, 0) @@ -3173,6 +3173,23 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel); + /* It can be that motorola_intel is wrongly mapped, let's try inverting it */ + if ((2+NumDirEntries*12) > value_len) { + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Potentially invalid endianess, trying again with different endianness before imminent failure."); + + ImageInfo->motorola_intel = ImageInfo->motorola_intel == 0 ? 1 : 0; + NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel); + } + + if ((2+NumDirEntries*12) > value_len) { + 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); + return FALSE; + } + if ((dir_start - value_ptr) > value_len - (2+NumDirEntries*12)) { + 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); + return FALSE; + } + switch (maker_note->offset_mode) { case MN_OFFSET_MAKER: offset_base = value_ptr; @@ -3203,15 +3220,6 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu break; } - if ((2+NumDirEntries*12) > value_len) { - 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); - return FALSE; - } - if ((dir_start - value_ptr) > value_len - (2+NumDirEntries*12)) { - 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); - return FALSE; - } - for (de=0;deWB27S$UZjI`P>O(vo!+Df7O*lPDsm7I5fl-z5CS3yf*_)T zB1I7!HpC9-QSm4$Dk^zvLOdt;{mbXw`@iqK`?)tWe)szAwb$OWXH7|rnaI4)e2PRp zT-;p{hGD1yR>XX^v&1T?9ly6W(4x93vwPEP*`6!?OLL z71(+Zv=%#t1lo{2&JbuL(2`)^0al=iF^ENiG&Lp>AH9RZ^52EZjLa!*V2n_C2Nm6b zb{FV$tCNcCK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