@@ -324,6 +324,8 @@ static int fill_marker_resource(xmlNodePtr marker_resource_elem,
324324 if (xmlStrcmp (element -> name , "Marker" ) == 0 ) {
325325 void * tmp ;
326326
327+ if (marker_resource -> marker_count == UINT32_MAX )
328+ return AVERROR (ENOMEM );
327329 tmp = av_realloc_array (marker_resource -> markers ,
328330 marker_resource -> marker_count + 1 ,
329331 sizeof (FFIMFMarker ));
@@ -384,6 +386,9 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
384386 if (!resource_list_elem )
385387 return 0 ;
386388 resource_elem_count = xmlChildElementCount (resource_list_elem );
389+ if (resource_elem_count > UINT32_MAX
390+ || cpl -> main_markers_track -> resource_count > UINT32_MAX - resource_elem_count )
391+ return AVERROR (ENOMEM );
387392 tmp = av_realloc_array (cpl -> main_markers_track -> resources ,
388393 cpl -> main_markers_track -> resource_count + resource_elem_count ,
389394 sizeof (FFIMFMarkerResource ));
@@ -456,6 +461,8 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp
456461
457462 /* create a main audio virtual track if none exists for the sequence */
458463 if (!vt ) {
464+ if (cpl -> main_audio_track_count == UINT32_MAX )
465+ return AVERROR (ENOMEM );
459466 tmp = av_realloc_array (cpl -> main_audio_tracks ,
460467 cpl -> main_audio_track_count + 1 ,
461468 sizeof (FFIMFTrackFileVirtualTrack ));
@@ -473,6 +480,9 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp
473480 if (!resource_list_elem )
474481 return 0 ;
475482 resource_elem_count = xmlChildElementCount (resource_list_elem );
483+ if (resource_elem_count > UINT32_MAX
484+ || vt -> resource_count > UINT32_MAX - resource_elem_count )
485+ return AVERROR (ENOMEM );
476486 tmp = av_fast_realloc (vt -> resources ,
477487 & vt -> resources_alloc_sz ,
478488 (vt -> resource_count + resource_elem_count ) * sizeof (FFIMFTrackFileResource ));
@@ -546,6 +556,10 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL
546556 if (!resource_list_elem )
547557 return 0 ;
548558 resource_elem_count = xmlChildElementCount (resource_list_elem );
559+ if (resource_elem_count > UINT32_MAX
560+ || cpl -> main_image_2d_track -> resource_count > UINT32_MAX - resource_elem_count
561+ || (cpl -> main_image_2d_track -> resource_count + resource_elem_count ) > INT_MAX / sizeof (FFIMFTrackFileResource ))
562+ return AVERROR (ENOMEM );
549563 tmp = av_fast_realloc (cpl -> main_image_2d_track -> resources ,
550564 & cpl -> main_image_2d_track -> resources_alloc_sz ,
551565 (cpl -> main_image_2d_track -> resource_count + resource_elem_count ) * sizeof (FFIMFTrackFileResource ));
0 commit comments