@@ -1654,10 +1654,10 @@ static int exif_file_sections_free(image_info_type *ImageInfo)
1654
1654
/* {{{ exif_iif_add_value
1655
1655
Add a value to image_info
1656
1656
*/
1657
- static void exif_iif_add_value (image_info_type * image_info , int section_index , char * name , int tag , int format , int length , void * value , int motorola_intel )
1657
+ static void exif_iif_add_value (image_info_type * image_info , int section_index , char * name , int tag , int format , int length , void * value , size_t value_len , int motorola_intel )
1658
1658
{
1659
1659
size_t idex ;
1660
- void * vptr ;
1660
+ void * vptr , * vptr_end ;
1661
1661
image_info_value * info_value ;
1662
1662
image_info_data * info_data ;
1663
1663
image_info_data * list ;
@@ -1679,8 +1679,12 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
1679
1679
1680
1680
switch (format ) {
1681
1681
case TAG_FMT_STRING :
1682
+ if (length > value_len ) {
1683
+ exif_error_docref ("exif_iif_add_value" EXIFERR_CC , image_info , E_WARNING , "length > value_len: %d > %zu" , length , value_len );
1684
+ value = NULL ;
1685
+ }
1682
1686
if (value ) {
1683
- length = php_strnlen (value , length );
1687
+ length = ( int ) php_strnlen (value , length );
1684
1688
info_value -> s = estrndup (value , length );
1685
1689
info_data -> length = length ;
1686
1690
} else {
@@ -1702,6 +1706,10 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
1702
1706
if (!length )
1703
1707
break ;
1704
1708
case TAG_FMT_UNDEFINED :
1709
+ if (length > value_len ) {
1710
+ exif_error_docref ("exif_iif_add_value" EXIFERR_CC , image_info , E_WARNING , "length > value_len: %d > %zu" , length , value_len );
1711
+ value = NULL ;
1712
+ }
1705
1713
if (value ) {
1706
1714
if (tag == TAG_MAKER_NOTE ) {
1707
1715
length = (int ) php_strnlen (value , length );
@@ -1732,7 +1740,12 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
1732
1740
} else {
1733
1741
info_value = & info_data -> value ;
1734
1742
}
1743
+ vptr_end = value + value_len ;
1735
1744
for (idex = 0 ,vptr = value ; idex < (size_t )length ; idex ++ ,vptr = (char * ) vptr + php_tiff_bytes_per_format [format ]) {
1745
+ if (vptr_end - vptr < php_tiff_bytes_per_format [format ]) {
1746
+ exif_error_docref ("exif_iif_add_value" EXIFERR_CC , image_info , E_WARNING , "Value too short" );
1747
+ break ;
1748
+ }
1736
1749
if (length > 1 ) {
1737
1750
info_value = & info_data -> value .list [idex ];
1738
1751
}
@@ -1768,7 +1781,7 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
1768
1781
php_error_docref (NULL , E_WARNING , "Found value of type single" );
1769
1782
#endif
1770
1783
info_value -> f = * (float * )value ;
1771
-
1784
+ break ;
1772
1785
case TAG_FMT_DOUBLE :
1773
1786
#ifdef EXIF_DEBUG
1774
1787
php_error_docref (NULL , E_WARNING , "Found value of type double" );
@@ -1786,9 +1799,9 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
1786
1799
/* {{{ exif_iif_add_tag
1787
1800
Add a tag from IFD to image_info
1788
1801
*/
1789
- static void exif_iif_add_tag (image_info_type * image_info , int section_index , char * name , int tag , int format , size_t length , void * value )
1802
+ static void exif_iif_add_tag (image_info_type * image_info , int section_index , char * name , int tag , int format , size_t length , void * value , size_t value_len )
1790
1803
{
1791
- exif_iif_add_value (image_info , section_index , name , tag , format , (int )length , value , image_info -> motorola_intel );
1804
+ exif_iif_add_value (image_info , section_index , name , tag , format , (int )length , value , value_len , image_info -> motorola_intel );
1792
1805
}
1793
1806
/* }}} */
1794
1807
@@ -2209,7 +2222,7 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im
2209
2222
*/
2210
2223
static void exif_process_COM (image_info_type * image_info , char * value , size_t length )
2211
2224
{
2212
- exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_STRING , length - 2 , value + 2 );
2225
+ exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_STRING , length - 2 , value + 2 , length - 2 );
2213
2226
}
2214
2227
/* }}} */
2215
2228
@@ -2224,17 +2237,17 @@ static void exif_process_CME (image_info_type *image_info, char *value, size_t l
2224
2237
if (length > 3 ) {
2225
2238
switch (value [2 ]) {
2226
2239
case 0 :
2227
- exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_UNDEFINED , length , value );
2240
+ exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_UNDEFINED , length , value ), length ;
2228
2241
break ;
2229
2242
case 1 :
2230
- exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_STRING , length , value );
2243
+ exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_STRING , length , value , length );
2231
2244
break ;
2232
2245
default :
2233
2246
php_error_docref (NULL , E_NOTICE , "Undefined JPEG2000 comment encoding" );
2234
2247
break ;
2235
2248
}
2236
2249
} else {
2237
- exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_UNDEFINED , 0 , NULL );
2250
+ exif_iif_add_tag (image_info , SECTION_COMMENT , "Comment" , TAG_COMPUTED_VALUE , TAG_FMT_UNDEFINED , 0 , NULL , 0 );
2238
2251
php_error_docref (NULL , E_NOTICE , "JPEG2000 comment section too small" );
2239
2252
}
2240
2253
}
@@ -2827,7 +2840,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
2827
2840
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 )
2828
2841
{
2829
2842
size_t length ;
2830
- int tag , format , components ;
2843
+ unsigned int tag , format , components ;
2831
2844
char * value_ptr , tagname [64 ], cbuf [32 ], * outside = NULL ;
2832
2845
size_t byte_count , offset_val , fpos , fgot ;
2833
2846
int64_t byte_count_signed ;
@@ -3138,7 +3151,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
3138
3151
}
3139
3152
}
3140
3153
}
3141
- exif_iif_add_tag (ImageInfo , section_index , exif_get_tagname (tag , tagname , sizeof (tagname ), tag_table ), tag , format , components , value_ptr );
3154
+ exif_iif_add_tag (ImageInfo , section_index , exif_get_tagname (tag , tagname , sizeof (tagname ), tag_table ), tag , format , components , value_ptr , byte_count );
3142
3155
EFREE_IF (outside );
3143
3156
return TRUE;
3144
3157
}
@@ -3296,10 +3309,10 @@ static void exif_process_APP12(image_info_type *ImageInfo, char *buffer, size_t
3296
3309
size_t l1 , l2 = 0 ;
3297
3310
3298
3311
if ((l1 = php_strnlen (buffer + 2 , length - 2 )) > 0 ) {
3299
- exif_iif_add_tag (ImageInfo , SECTION_APP12 , "Company" , TAG_NONE , TAG_FMT_STRING , l1 , buffer + 2 );
3312
+ exif_iif_add_tag (ImageInfo , SECTION_APP12 , "Company" , TAG_NONE , TAG_FMT_STRING , l1 , buffer + 2 , l1 );
3300
3313
if (length > 2 + l1 + 1 ) {
3301
3314
l2 = php_strnlen (buffer + 2 + l1 + 1 , length - 2 - l1 - 1 );
3302
- exif_iif_add_tag (ImageInfo , SECTION_APP12 , "Info" , TAG_NONE , TAG_FMT_STRING , l2 , buffer + 2 + l1 + 1 );
3315
+ exif_iif_add_tag (ImageInfo , SECTION_APP12 , "Info" , TAG_NONE , TAG_FMT_STRING , l2 , buffer + 2 + l1 + 1 , l2 );
3303
3316
}
3304
3317
}
3305
3318
#ifdef EXIF_DEBUG
@@ -4100,7 +4113,7 @@ PHP_FUNCTION(exif_read_data)
4100
4113
if (ImageInfo .Thumbnail .size ) {
4101
4114
if (read_thumbnail ) {
4102
4115
/* not exif_iif_add_str : this is a buffer */
4103
- exif_iif_add_tag (& ImageInfo , SECTION_THUMBNAIL , "THUMBNAIL" , TAG_NONE , TAG_FMT_UNDEFINED , ImageInfo .Thumbnail .size , ImageInfo .Thumbnail .data );
4116
+ exif_iif_add_tag (& ImageInfo , SECTION_THUMBNAIL , "THUMBNAIL" , TAG_NONE , TAG_FMT_UNDEFINED , ImageInfo .Thumbnail .size , ImageInfo .Thumbnail .data , ImageInfo . Thumbnail . size );
4104
4117
}
4105
4118
if (!ImageInfo .Thumbnail .width || !ImageInfo .Thumbnail .height ) {
4106
4119
/* try to evaluate if thumbnail data is present */
0 commit comments