Skip to content

Commit f0f84ad

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents 3fd68fd + e76dea4 commit f0f84ad

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

ext/exif/exif.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,14 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
31713171
}
31723172
/* }}} */
31733173

3174+
#define REQUIRE_NON_EMPTY() do { \
3175+
if (byte_count == 0) { \
3176+
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Cannot be empty", tag, exif_get_tagname(tag, tagname, -12, tag_table)); \
3177+
return FALSE; \
3178+
} \
3179+
} while (0)
3180+
3181+
31743182
/* {{{ exif_process_IFD_TAG
31753183
* Process one of the nested IFDs directories. */
31763184
static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, char *offset_base, size_t IFDlength, size_t displacement, int section_index, int ReadNextIFD, tag_table_type tag_table)
@@ -3288,8 +3296,12 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
32883296
}
32893297
#endif
32903298

3299+
/* NB: The following code may not assume that there is at least one component!
3300+
* byte_count may be zero! */
3301+
32913302
if (section_index==SECTION_THUMBNAIL) {
32923303
if (!ImageInfo->Thumbnail.data) {
3304+
REQUIRE_NON_EMPTY();
32933305
switch(tag) {
32943306
case TAG_IMAGEWIDTH:
32953307
case TAG_COMP_IMAGE_WIDTH:
@@ -3372,6 +3384,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
33723384
case TAG_FNUMBER:
33733385
/* Simplest way of expressing aperture, so I trust it the most.
33743386
(overwrite previously computed value if there is one) */
3387+
REQUIRE_NON_EMPTY();
33753388
ImageInfo->ApertureFNumber = (float)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel);
33763389
break;
33773390

@@ -3380,6 +3393,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
33803393
/* More relevant info always comes earlier, so only use this field if we don't
33813394
have appropriate aperture information yet. */
33823395
if (ImageInfo->ApertureFNumber == 0) {
3396+
REQUIRE_NON_EMPTY();
33833397
ImageInfo->ApertureFNumber
33843398
= expf(exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel)*logf(2.0)*0.5);
33853399
}
@@ -3391,6 +3405,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
33913405
SHUTTERSPEED comes after EXPOSURE TIME
33923406
*/
33933407
if (ImageInfo->ExposureTime == 0) {
3408+
REQUIRE_NON_EMPTY();
33943409
ImageInfo->ExposureTime
33953410
= expf(-exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel)*logf(2.0));
33963411
}
@@ -3400,20 +3415,24 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
34003415
break;
34013416

34023417
case TAG_COMP_IMAGE_WIDTH:
3418+
REQUIRE_NON_EMPTY();
34033419
ImageInfo->ExifImageWidth = exif_convert_any_to_int(value_ptr, exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
34043420
break;
34053421

34063422
case TAG_FOCALPLANE_X_RES:
3423+
REQUIRE_NON_EMPTY();
34073424
ImageInfo->FocalplaneXRes = exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel);
34083425
break;
34093426

34103427
case TAG_SUBJECT_DISTANCE:
34113428
/* Inidcates the distacne the autofocus camera is focused to.
34123429
Tends to be less accurate as distance increases. */
3430+
REQUIRE_NON_EMPTY();
34133431
ImageInfo->Distance = (float)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel);
34143432
break;
34153433

34163434
case TAG_FOCALPLANE_RESOLUTION_UNIT:
3435+
REQUIRE_NON_EMPTY();
34173436
switch((int)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel)) {
34183437
case 1: ImageInfo->FocalplaneUnits = 25.4; break; /* inch */
34193438
case 2:
@@ -3456,6 +3475,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
34563475
case TAG_GPS_IFD_POINTER:
34573476
case TAG_INTEROP_IFD_POINTER:
34583477
if (ReadNextIFD) {
3478+
REQUIRE_NON_EMPTY();
34593479
char *Subdir_start;
34603480
int sub_section_index = 0;
34613481
switch(tag) {

ext/exif/tests/bug73737.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ Bug #73737 (Crash when parsing a tag format)
88
var_dump($exif);
99
?>
1010
--EXPECTF--
11+
Warning: exif_thumbnail(bug73737.tiff): Process tag(x0100=ImageWidth ): Cannot be empty in %s on line %d
12+
1113
Warning: exif_thumbnail(bug73737.tiff): Error in TIFF: filesize(x0030) less than start of IFD dir(x10102) in %s line %d
1214
bool(false)
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
OSS-Fuzz #17163: Out-of-bounds read due to tag with zero components
3+
--FILE--
4+
<?php
5+
6+
var_dump(exif_read_data(__DIR__ . '/tag_with_illegal_zero_components.jpeg'));
7+
8+
?>
9+
--EXPECTF--
10+
Warning: exif_read_data(tag_with_illegal_zero_components.jpeg): Process tag(x0202=JPEGInterch): Cannot be empty in %s on line %d
11+
12+
Warning: exif_read_data(tag_with_illegal_zero_components.jpeg): File structure corrupted in %s on line %d
13+
14+
Warning: exif_read_data(tag_with_illegal_zero_components.jpeg): Invalid JPEG file in %s on line %d
15+
bool(false)

0 commit comments

Comments
 (0)