[FFmpeg-devel] [PATCH 5/8] avformat/matroskaenc: Use av_fast_realloc_array for index entries

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Jul 6 18:10:13 EEST 2022


Tomas Härdin:
> tis 2022-07-05 klockan 22:26 +0200 skrev Andreas Rheinhardt:
>>
>> -    entries = av_realloc_array(entries, cues->num_entries + 1,
>> sizeof(mkv_cuepoint));
>> -    if (!entries)
>> -        return AVERROR(ENOMEM);
>> -    cues->entries = entries;
>> +    ret = av_fast_realloc_array(&cues->entries, &cues-
>>> allocated_entries,
>> +                                cues->num_entries + 1,
>> +                                MAX_SUPPORTED_EBML_LENGTH /
>> MIN_CUETRACKPOS_SIZE,
> 
> Looks fine since MAX_SUPPORTED_EBML_LENGTH <= INT_MAX. Even SIZE_MAX /
> MIN_CUETRACKPOS_SIZE would work. Maybe we can could switch
> MAX_SUPPORTED_EBML_LENGTH to
> 
>  #define MAX_SUPPORTED_EBML_LENGTH FFMIN(MAX_EBML_LENGTH, SIZE_MAX)
> 
> ?
> 

To quote the comment for MAX_SUPPORTED_EBML_LENGTH:
"/* The dynamic buffer API we rely upon has a limit of INT_MAX;
 * and so has avio_write(). */"
And I don't get why MAX_SUPPORTED_EBML_LENGTH <= INT_MAX is even
relevant here. (Do you worry that MAX_SUPPORTED_EBML_LENGTH /
MIN_CUETRACKPOS_SIZE might not be representable in a size_t? Thinking
about this, defining it as FFMIN3(MAX_EBML_LENGTH, INT_MAX, SIZE_MAX) is
better.)

- Andreas


More information about the ffmpeg-devel mailing list