[FFmpeg-devel,2/2] avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays

Submitted by James Almer on Sept. 3, 2019, 9:56 p.m.

Details

Message ID 20190903215658.745-2-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Sept. 3, 2019, 9:56 p.m.
Speeds up the process considerably.

Fixes ticket #8109.

Suggested-by: nevcairiel
Suggested-by: cehoyos
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Carl Eugen Hoyos Sept. 3, 2019, 10:40 p.m.
> Am 03.09.2019 um 23:56 schrieb James Almer <jamrial@gmail.com>:
> 
> Speeds up the process considerably.
> 
> Fixes ticket #8109.
> 
> Suggested-by: nevcairiel
> Suggested-by: cehoyos
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/matroskadec.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 439ee462a5..fe45c4fd7f 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,9 @@ 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 = av_fast_realloc(list->elem,
> +                                            &list->alloc_elem_size,
> +                                            (list->nb_elem + 1) * syntax->list_elem_size);

Is it not necessary to check for an overflow of size * elem?

Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 439ee462a5..fe45c4fd7f 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,9 @@  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 = 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;