Skip to content

Commit 3789aab

Browse files
committed
MFH: Allow ifd start at offset other than 00000008h and provide testcase.
1 parent c326e43 commit 3789aab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ext/exif/exif.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,8 @@ static void exif_process_IFD_in_JPEG(image_info_type *ImageInfo, char *DirStart,
16061606
*/
16071607
static void exif_process_TIFF_in_JPEG(image_info_type *ImageInfo, char *CharBuf, unsigned int length)
16081608
{
1609+
unsigned exif_value_2a, offset_of_ifd;
1610+
16091611
/* set the thumbnail stuff to nothing so we can test to see if they get set up */
16101612
if (memcmp(CharBuf, "II", 2) == 0) {
16111613
ImageInfo->motorola_intel = 0;
@@ -1617,14 +1619,15 @@ static void exif_process_TIFF_in_JPEG(image_info_type *ImageInfo, char *CharBuf,
16171619
}
16181620

16191621
/* Check the next two values for correctness. */
1620-
if (php_ifd_get16u(CharBuf+2, ImageInfo->motorola_intel) != 0x2a
1621-
|| php_ifd_get32u(CharBuf+4, ImageInfo->motorola_intel) != 0x08) {
1622+
exif_value_2a = php_ifd_get16u(CharBuf+2, ImageInfo->motorola_intel);
1623+
offset_of_ifd = php_ifd_get32u(CharBuf+4, ImageInfo->motorola_intel);
1624+
if ( exif_value_2a != 0x2a || offset_of_ifd < 0x08) {
16221625
php_error(E_WARNING, "Invalid TIFF start (1)");
16231626
return;
16241627
}
16251628

16261629
/* First directory starts at offset 8. Offsets starts at 0. */
1627-
exif_process_IFD_in_JPEG(ImageInfo, CharBuf+8, CharBuf, length/*-14*/, SECTION_IFD0);
1630+
exif_process_IFD_in_JPEG(ImageInfo, CharBuf+offset_of_ifd, CharBuf, length/*-14*/, SECTION_IFD0);
16281631

16291632
#ifdef EXIF_DEBUG
16301633
php_error(E_NOTICE,"exif_process_TIFF_in_JPEG, done");

0 commit comments

Comments
 (0)