aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2019-09-03 18:45:04 -0300
committerJames Almer <jamrial@gmail.com>2019-09-04 16:30:46 -0300
commit3de33c6e76d52e70d69797cd75efe4600f4f12d6 (patch)
tree4a8152468c901a115a0dbf840fe76d507144d703
parent6a19167a6f03c932d15e078332b4968bbd2aa0ee (diff)
downloadffmpeg-3de33c6e76d52e70d69797cd75efe4600f4f12d6.tar.gz
avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays
Speeds up the process considerably. Fixes ticket #8109. Suggested-by: nevcairiel Suggested-by: cehoyos Signed-off-by: James Almer <jamrial@gmail.com> (cherry picked from commit 3b3150c45f1ebb3635e55e76b63439d8d62de85f)
-rw-r--r--libavformat/matroskadec.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 439ee462a5..8c4ff30935 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,13 @@ 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 (!newelem)
return AVERROR(ENOMEM);
list->elem = newelem;
@@ -1490,6 +1496,7 @@ static void ebml_free(EbmlSyntax *syntax, void *data)
ebml_free(syntax[i].def.n, ptr);
av_freep(&list->elem);
list->nb_elem = 0;
+ list->alloc_elem_size = 0;
} else
ebml_free(syntax[i].def.n, data_off);
default: