@@ -3152,7 +3152,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3152
3152
break ;
3153
3153
}
3154
3154
3155
- if (maker_note -> offset >= value_len ) {
3155
+ if (value_len < 2 || maker_note -> offset >= value_len - 1 ) {
3156
3156
/* Do not go past the value end */
3157
3157
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 );
3158
3158
return FALSE;
@@ -3207,6 +3207,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
3207
3207
#endif
3208
3208
default :
3209
3209
case MN_OFFSET_NORMAL :
3210
+ data_len = value_len ;
3210
3211
break ;
3211
3212
}
3212
3213
@@ -3930,7 +3931,7 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3930
3931
return FALSE;
3931
3932
marker = c ;
3932
3933
length = php_jpg_get16 (data + pos );
3933
- if (pos + length >= ImageInfo -> Thumbnail .size ) {
3934
+ if (length > ImageInfo -> Thumbnail . size || pos >= ImageInfo -> Thumbnail .size - length ) {
3934
3935
return FALSE;
3935
3936
}
3936
3937
#ifdef EXIF_DEBUG
@@ -3951,6 +3952,10 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3951
3952
case M_SOF14 :
3952
3953
case M_SOF15 :
3953
3954
/* handle SOFn block */
3955
+ if (length < 8 || ImageInfo -> Thumbnail .size - 8 < pos ) {
3956
+ /* exif_process_SOFn needs 8 bytes */
3957
+ return FALSE;
3958
+ }
3954
3959
exif_process_SOFn (data + pos , marker , & sof_info );
3955
3960
ImageInfo -> Thumbnail .height = sof_info .height ;
3956
3961
ImageInfo -> Thumbnail .width = sof_info .width ;
@@ -3988,19 +3993,19 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
3988
3993
tag_table_type tag_table = exif_get_tag_table (section_index );
3989
3994
3990
3995
if (ImageInfo -> ifd_nesting_level > MAX_IFD_NESTING_LEVEL ) {
3991
- return FALSE;
3992
- }
3996
+ return FALSE;
3997
+ }
3993
3998
3994
- if (ImageInfo -> FileSize >= dir_offset + 2 ) {
3999
+ if (ImageInfo -> FileSize >= 2 && ImageInfo -> FileSize - 2 >= dir_offset ) {
3995
4000
sn = exif_file_sections_add (ImageInfo , M_PSEUDO , 2 , NULL );
3996
4001
#ifdef EXIF_DEBUG
3997
4002
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 );
3998
4003
#endif
3999
4004
php_stream_seek (ImageInfo -> infile , dir_offset , SEEK_SET ); /* we do not know the order of sections */
4000
4005
php_stream_read (ImageInfo -> infile , (char * )ImageInfo -> file .list [sn ].data , 2 );
4001
4006
num_entries = php_ifd_get16u (ImageInfo -> file .list [sn ].data , ImageInfo -> motorola_intel );
4002
- dir_size = 2 /*num dir entries*/ + 12 /*length of entry*/ * num_entries + 4 /* offset to next ifd (points to thumbnail or NULL)*/ ;
4003
- if (ImageInfo -> FileSize >= dir_offset + dir_size ) {
4007
+ dir_size = 2 /*num dir entries*/ + 12 /*length of entry*/ * ( size_t ) num_entries + 4 /* offset to next ifd (points to thumbnail or NULL)*/ ;
4008
+ if (ImageInfo -> FileSize >= dir_size && ImageInfo -> FileSize - dir_size >= dir_offset ) {
4004
4009
#ifdef EXIF_DEBUG
4005
4010
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 );
4006
4011
#endif
@@ -4083,9 +4088,9 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
4083
4088
}
4084
4089
}
4085
4090
}
4086
- if (ImageInfo -> FileSize >= dir_offset + ImageInfo -> file .list [sn ].size ) {
4091
+ if (ImageInfo -> FileSize >= ImageInfo -> file . list [ sn ]. size && ImageInfo -> FileSize - ImageInfo -> file .list [sn ].size >= dir_offset ) {
4087
4092
if (ifd_size > dir_size ) {
4088
- if (dir_offset + ifd_size > ImageInfo -> FileSize ) {
4093
+ if (ImageInfo -> FileSize < ifd_size || dir_offset > ImageInfo -> FileSize - ifd_size ) {
4089
4094
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 );
4090
4095
return FALSE;
4091
4096
}
@@ -4682,7 +4687,9 @@ PHP_FUNCTION(exif_thumbnail)
4682
4687
ZVAL_STRINGL (return_value , ImageInfo .Thumbnail .data , ImageInfo .Thumbnail .size );
4683
4688
if (arg_c >= 3 ) {
4684
4689
if (!ImageInfo .Thumbnail .width || !ImageInfo .Thumbnail .height ) {
4685
- exif_scan_thumbnail (& ImageInfo );
4690
+ if (!exif_scan_thumbnail (& ImageInfo )) {
4691
+ ImageInfo .Thumbnail .width = ImageInfo .Thumbnail .height = 0 ;
4692
+ }
4686
4693
}
4687
4694
zval_dtor (z_width );
4688
4695
zval_dtor (z_height );
0 commit comments