[FFmpeg-devel] [PATCH 2/2 v2] avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays
James Almer
jamrial at gmail.com
Wed Sep 4 04:53:24 EEST 2019
On 9/3/2019 8:36 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Speeds up the process considerably.
>>
>> Fixes ticket #8109.
>>
>> Suggested-by: nevcairiel
>> Suggested-by: cehoyos
>> Signed-off-by: James Almer <jamrial at gmail.com>
>> ---
>> libavformat/matroskadec.c | 12 ++++++++++--
>> 1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 439ee462a5..0f227eb33d 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -110,6 +110,7 @@ typedef const struct EbmlSyntax {
>>
>> typedef struct EbmlList {
>> int nb_elem;
>> + unsigned int alloc_elem_size;
>> void *elem;
>> } EbmlList;
>>
>> @@ -1236,8 +1237,14 @@ static int ebml_parse(MatroskaDemuxContext *matroska,
>> data = (char *) data + syntax->data_offset;
>> if (syntax->list_elem_size) {
>> EbmlList *list = data;
>> - void *newelem = av_realloc_array(list->elem, list->nb_elem + 1,
>> - syntax->list_elem_size);
>> + void *newelem;
>> +
>> + if ((unsigned)list->nb_elem + 1 >= UINT_MAX / syntax->list_elem_size)
>> + return AVERROR(ENOMEM);
>> +
>> + newelem = av_fast_realloc(list->elem,
>> + &list->alloc_elem_size,
>> + (list->nb_elem + 1) * syntax->list_elem_size);
> If this fails, list->alloc_elem_size will be zero, yet list->elem and
> list->nb_elem might be non NULL/zero. I actually think that this will
> probably work, but it is nevertheless ugly.
It should work.
I'll push this tomorrow if no one objects, then backport to supported
branches.
More information about the ffmpeg-devel
mailing list