@@ -4291,6 +4291,7 @@ static bool exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offs
42914291 return result ;
42924292}
42934293
4294+ /* Returns the size of the header, which must be smaller than the size of the box. */
42944295static int exif_isobmff_parse_box (unsigned char * buf , isobmff_box_type * box )
42954296{
42964297 box -> size = php_ifd_get32u (buf , 1 );
@@ -4312,6 +4313,9 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43124313
43134314 for (box_offset = data + 4 ; box_offset + 16 < end ; box_offset += box .size ) {
43144315 header_size = exif_isobmff_parse_box (box_offset , & box );
4316+ if (box .size < header_size ) {
4317+ return ;
4318+ }
43154319 if (box .type == FOURCC ("iinf" )) {
43164320 p = box_offset + header_size ;
43174321 if (p >= end ) {
@@ -4334,6 +4338,9 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43344338 }
43354339 for (i = 0 ; i < item_count && p + 20 < end ; i ++ ) {
43364340 header_size = exif_isobmff_parse_box (p , & item );
4341+ if (item .size < header_size ) {
4342+ return ;
4343+ }
43374344 if (p + header_size + 12 >= end ) {
43384345 return ;
43394346 }
@@ -4396,6 +4403,9 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf
43964403 break ;
43974404 }
43984405 box_header_size = exif_isobmff_parse_box (buf , & box );
4406+ if (box .size < box_header_size ) {
4407+ break ;
4408+ }
43994409 if (box .type == FOURCC ("meta" )) {
44004410 limit = box .size - box_header_size ;
44014411 if (limit < 36 ) {
0 commit comments