@@ -3229,6 +3229,14 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3229
3229
}
3230
3230
/* }}} */
3231
3231
3232
+ #define REQUIRE_NON_EMPTY () do { \
3233
+ if (byte_count == 0) { \
3234
+ 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)); \
3235
+ return FALSE; \
3236
+ } \
3237
+ } while (0)
3238
+
3239
+
3232
3240
/* {{{ exif_process_IFD_TAG
3233
3241
* Process one of the nested IFDs directories. */
3234
3242
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 )
@@ -3346,8 +3354,12 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3346
3354
}
3347
3355
#endif
3348
3356
3357
+ /* NB: The following code may not assume that there is at least one component!
3358
+ * byte_count may be zero! */
3359
+
3349
3360
if (section_index == SECTION_THUMBNAIL ) {
3350
3361
if (!ImageInfo -> Thumbnail .data ) {
3362
+ REQUIRE_NON_EMPTY ();
3351
3363
switch (tag ) {
3352
3364
case TAG_IMAGEWIDTH :
3353
3365
case TAG_COMP_IMAGE_WIDTH :
@@ -3430,6 +3442,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3430
3442
case TAG_FNUMBER :
3431
3443
/* Simplest way of expressing aperture, so I trust it the most.
3432
3444
(overwrite previously computed value if there is one) */
3445
+ REQUIRE_NON_EMPTY ();
3433
3446
ImageInfo -> ApertureFNumber = (float )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3434
3447
break ;
3435
3448
@@ -3438,6 +3451,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3438
3451
/* More relevant info always comes earlier, so only use this field if we don't
3439
3452
have appropriate aperture information yet. */
3440
3453
if (ImageInfo -> ApertureFNumber == 0 ) {
3454
+ REQUIRE_NON_EMPTY ();
3441
3455
ImageInfo -> ApertureFNumber
3442
3456
= (float )exp (exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )* log (2 )* 0.5 );
3443
3457
}
@@ -3449,6 +3463,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3449
3463
SHUTTERSPEED comes after EXPOSURE TIME
3450
3464
*/
3451
3465
if (ImageInfo -> ExposureTime == 0 ) {
3466
+ REQUIRE_NON_EMPTY ();
3452
3467
ImageInfo -> ExposureTime
3453
3468
= (float )(1 /exp (exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )* log (2 )));
3454
3469
}
@@ -3458,20 +3473,24 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3458
3473
break ;
3459
3474
3460
3475
case TAG_COMP_IMAGE_WIDTH :
3476
+ REQUIRE_NON_EMPTY ();
3461
3477
ImageInfo -> ExifImageWidth = exif_convert_any_to_int (value_ptr , exif_rewrite_tag_format_to_unsigned (format ), ImageInfo -> motorola_intel );
3462
3478
break ;
3463
3479
3464
3480
case TAG_FOCALPLANE_X_RES :
3481
+ REQUIRE_NON_EMPTY ();
3465
3482
ImageInfo -> FocalplaneXRes = exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3466
3483
break ;
3467
3484
3468
3485
case TAG_SUBJECT_DISTANCE :
3469
3486
/* Inidcates the distacne the autofocus camera is focused to.
3470
3487
Tends to be less accurate as distance increases. */
3488
+ REQUIRE_NON_EMPTY ();
3471
3489
ImageInfo -> Distance = (float )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3472
3490
break ;
3473
3491
3474
3492
case TAG_FOCALPLANE_RESOLUTION_UNIT :
3493
+ REQUIRE_NON_EMPTY ();
3475
3494
switch ((int )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )) {
3476
3495
case 1 : ImageInfo -> FocalplaneUnits = 25.4 ; break ; /* inch */
3477
3496
case 2 :
@@ -3514,6 +3533,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3514
3533
case TAG_GPS_IFD_POINTER :
3515
3534
case TAG_INTEROP_IFD_POINTER :
3516
3535
if (ReadNextIFD ) {
3536
+ REQUIRE_NON_EMPTY ();
3517
3537
char * Subdir_start ;
3518
3538
int sub_section_index = 0 ;
3519
3539
switch (tag ) {
0 commit comments