@@ -3171,6 +3171,14 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3171
3171
}
3172
3172
/* }}} */
3173
3173
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
+
3174
3182
/* {{{ exif_process_IFD_TAG
3175
3183
* Process one of the nested IFDs directories. */
3176
3184
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
3288
3296
}
3289
3297
#endif
3290
3298
3299
+ /* NB: The following code may not assume that there is at least one component!
3300
+ * byte_count may be zero! */
3301
+
3291
3302
if (section_index == SECTION_THUMBNAIL ) {
3292
3303
if (!ImageInfo -> Thumbnail .data ) {
3304
+ REQUIRE_NON_EMPTY ();
3293
3305
switch (tag ) {
3294
3306
case TAG_IMAGEWIDTH :
3295
3307
case TAG_COMP_IMAGE_WIDTH :
@@ -3372,6 +3384,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3372
3384
case TAG_FNUMBER :
3373
3385
/* Simplest way of expressing aperture, so I trust it the most.
3374
3386
(overwrite previously computed value if there is one) */
3387
+ REQUIRE_NON_EMPTY ();
3375
3388
ImageInfo -> ApertureFNumber = (float )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3376
3389
break ;
3377
3390
@@ -3380,6 +3393,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3380
3393
/* More relevant info always comes earlier, so only use this field if we don't
3381
3394
have appropriate aperture information yet. */
3382
3395
if (ImageInfo -> ApertureFNumber == 0 ) {
3396
+ REQUIRE_NON_EMPTY ();
3383
3397
ImageInfo -> ApertureFNumber
3384
3398
= expf (exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )* logf (2.0 )* 0.5 );
3385
3399
}
@@ -3391,6 +3405,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3391
3405
SHUTTERSPEED comes after EXPOSURE TIME
3392
3406
*/
3393
3407
if (ImageInfo -> ExposureTime == 0 ) {
3408
+ REQUIRE_NON_EMPTY ();
3394
3409
ImageInfo -> ExposureTime
3395
3410
= expf (- exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )* logf (2.0 ));
3396
3411
}
@@ -3400,20 +3415,24 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3400
3415
break ;
3401
3416
3402
3417
case TAG_COMP_IMAGE_WIDTH :
3418
+ REQUIRE_NON_EMPTY ();
3403
3419
ImageInfo -> ExifImageWidth = exif_convert_any_to_int (value_ptr , exif_rewrite_tag_format_to_unsigned (format ), ImageInfo -> motorola_intel );
3404
3420
break ;
3405
3421
3406
3422
case TAG_FOCALPLANE_X_RES :
3423
+ REQUIRE_NON_EMPTY ();
3407
3424
ImageInfo -> FocalplaneXRes = exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3408
3425
break ;
3409
3426
3410
3427
case TAG_SUBJECT_DISTANCE :
3411
3428
/* Inidcates the distacne the autofocus camera is focused to.
3412
3429
Tends to be less accurate as distance increases. */
3430
+ REQUIRE_NON_EMPTY ();
3413
3431
ImageInfo -> Distance = (float )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel );
3414
3432
break ;
3415
3433
3416
3434
case TAG_FOCALPLANE_RESOLUTION_UNIT :
3435
+ REQUIRE_NON_EMPTY ();
3417
3436
switch ((int )exif_convert_any_format (value_ptr , format , ImageInfo -> motorola_intel )) {
3418
3437
case 1 : ImageInfo -> FocalplaneUnits = 25.4 ; break ; /* inch */
3419
3438
case 2 :
@@ -3456,6 +3475,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3456
3475
case TAG_GPS_IFD_POINTER :
3457
3476
case TAG_INTEROP_IFD_POINTER :
3458
3477
if (ReadNextIFD ) {
3478
+ REQUIRE_NON_EMPTY ();
3459
3479
char * Subdir_start ;
3460
3480
int sub_section_index = 0 ;
3461
3481
switch (tag ) {
0 commit comments