@@ -3125,7 +3125,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3125
3125
break ;
3126
3126
}
3127
3127
3128
- if (maker_note -> offset >= value_len ) {
3128
+ if (value_len < 2 || maker_note -> offset >= value_len - 1 ) {
3129
3129
/* Do not go past the value end */
3130
3130
exif_error_docref ("exif_read_data#error_ifd" EXIFERR_CC , ImageInfo , E_WARNING , "IFD data too short: 0x%04X offset 0x%04X" , value_len , maker_note -> offset );
3131
3131
return FALSE;
@@ -3180,6 +3180,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3180
3180
#endif
3181
3181
default :
3182
3182
case MN_OFFSET_NORMAL :
3183
+ data_len = value_len ;
3183
3184
break ;
3184
3185
}
3185
3186
@@ -3903,7 +3904,7 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3903
3904
return FALSE;
3904
3905
marker = c ;
3905
3906
length = php_jpg_get16 (data + pos );
3906
- if (pos + length >= ImageInfo -> Thumbnail .size ) {
3907
+ if (length > ImageInfo -> Thumbnail . size || pos >= ImageInfo -> Thumbnail .size - length ) {
3907
3908
return FALSE;
3908
3909
}
3909
3910
#ifdef EXIF_DEBUG
@@ -3924,6 +3925,10 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3924
3925
case M_SOF14 :
3925
3926
case M_SOF15 :
3926
3927
/* handle SOFn block */
3928
+ if (length < 8 || ImageInfo -> Thumbnail .size - 8 < pos ) {
3929
+ /* exif_process_SOFn needs 8 bytes */
3930
+ return FALSE;
3931
+ }
3927
3932
exif_process_SOFn (data + pos , marker , & sof_info );
3928
3933
ImageInfo -> Thumbnail .height = sof_info .height ;
3929
3934
ImageInfo -> Thumbnail .width = sof_info .width ;
@@ -3961,19 +3966,19 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
3961
3966
tag_table_type tag_table = exif_get_tag_table (section_index );
3962
3967
3963
3968
if (ImageInfo -> ifd_nesting_level > MAX_IFD_NESTING_LEVEL ) {
3964
- return FALSE;
3965
- }
3969
+ return FALSE;
3970
+ }
3966
3971
3967
- if (ImageInfo -> FileSize >= dir_offset + 2 ) {
3972
+ if (ImageInfo -> FileSize >= 2 && ImageInfo -> FileSize - 2 >= dir_offset ) {
3968
3973
sn = exif_file_sections_add (ImageInfo , M_PSEUDO , 2 , NULL );
3969
3974
#ifdef EXIF_DEBUG
3970
3975
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_NOTICE , "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)" , ImageInfo -> FileSize , dir_offset , 2 );
3971
3976
#endif
3972
3977
php_stream_seek (ImageInfo -> infile , dir_offset , SEEK_SET ); /* we do not know the order of sections */
3973
3978
php_stream_read (ImageInfo -> infile , (char * )ImageInfo -> file .list [sn ].data , 2 );
3974
3979
num_entries = php_ifd_get16u (ImageInfo -> file .list [sn ].data , ImageInfo -> motorola_intel );
3975
- dir_size = 2 /*num dir entries*/ + 12 /*length of entry*/ * num_entries + 4 /* offset to next ifd (points to thumbnail or NULL)*/ ;
3976
- if (ImageInfo -> FileSize >= dir_offset + dir_size ) {
3980
+ dir_size = 2 /*num dir entries*/ + 12 /*length of entry*/ * ( size_t ) num_entries + 4 /* offset to next ifd (points to thumbnail or NULL)*/ ;
3981
+ if (ImageInfo -> FileSize >= dir_size && ImageInfo -> FileSize - dir_size >= dir_offset ) {
3977
3982
#ifdef EXIF_DEBUG
3978
3983
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_NOTICE , "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X), IFD entries(%d)" , ImageInfo -> FileSize , dir_offset + 2 , dir_size - 2 , num_entries );
3979
3984
#endif
@@ -4056,9 +4061,9 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
4056
4061
}
4057
4062
}
4058
4063
}
4059
- if (ImageInfo -> FileSize >= dir_offset + ImageInfo -> file .list [sn ].size ) {
4064
+ if (ImageInfo -> FileSize >= ImageInfo -> file . list [ sn ]. size && ImageInfo -> FileSize - ImageInfo -> file .list [sn ].size >= dir_offset ) {
4060
4065
if (ifd_size > dir_size ) {
4061
- if (dir_offset + ifd_size > ImageInfo -> FileSize ) {
4066
+ if (ImageInfo -> FileSize < ifd_size || dir_offset > ImageInfo -> FileSize - ifd_size ) {
4062
4067
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_WARNING , "Error in TIFF: filesize(x%04X) less than size of IFD(x%04X + x%04X)" , ImageInfo -> FileSize , dir_offset , ifd_size );
4063
4068
return FALSE;
4064
4069
}
@@ -4655,7 +4660,9 @@ PHP_FUNCTION(exif_thumbnail)
4655
4660
ZVAL_STRINGL (return_value , ImageInfo .Thumbnail .data , ImageInfo .Thumbnail .size );
4656
4661
if (arg_c >= 3 ) {
4657
4662
if (!ImageInfo .Thumbnail .width || !ImageInfo .Thumbnail .height ) {
4658
- exif_scan_thumbnail (& ImageInfo );
4663
+ if (!exif_scan_thumbnail (& ImageInfo )) {
4664
+ ImageInfo .Thumbnail .width = ImageInfo .Thumbnail .height = 0 ;
4665
+ }
4659
4666
}
4660
4667
zval_ptr_dtor (z_width );
4661
4668
zval_ptr_dtor (z_height );
0 commit comments