[FFmpeg-devel,2/2] avformat/concatdec: add support for very long line sizes

Submitted by Marton Balint on Feb. 10, 2018, 5:12 p.m.

Details

Message ID 20180210171206.29686-2-cus@passwd.hu
State New
Headers show

Commit Message

Marton Balint Feb. 10, 2018, 5:12 p.m.
Fixes ticket #6761.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/concatdec.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Comments

Nicolas George Feb. 11, 2018, 1:45 p.m.
Marton Balint (2018-02-10):
> Fixes ticket #6761.
> 
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavformat/concatdec.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> index 178fac86cb..3e41a62a36 100644
> --- a/libavformat/concatdec.c
> +++ b/libavformat/concatdec.c
> @@ -24,6 +24,7 @@

>  #include "libavutil/opt.h"
>  #include "libavutil/parseutils.h"
>  #include "libavutil/timestamp.h"
> +#include "libavutil/bprint.h"

Nit: alphabetic order.

>  #include "avformat.h"
>  #include "internal.h"
>  #include "url.h"
> @@ -386,18 +387,18 @@ static int concat_read_close(AVFormatContext *avf)
>  static int concat_read_header(AVFormatContext *avf)
>  {
>      ConcatContext *cat = avf->priv_data;
> -    uint8_t buf[4096];
> +    AVBPrint bp;
>      uint8_t *cursor, *keyword;
> -    int ret, line = 0, i;
> +    int line = 0, i;
>      unsigned nb_files_alloc = 0;
>      ConcatFile *file = NULL;
> -    int64_t time = 0;
> +    int64_t ret, time = 0;
>  
> -    while (1) {
> -        if ((ret = ff_get_line(avf->pb, buf, sizeof(buf))) <= 0)
> -            break;
> +    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> +
> +    while ((ret = ff_read_line_to_bprint_overwrite(avf->pb, &bp)) >= 0) {
>          line++;
> -        cursor = buf;
> +        cursor = bp.str;
>          keyword = get_keyword(&cursor);
>          if (!*keyword || *keyword == '#')
>              continue;
> @@ -473,7 +474,7 @@ static int concat_read_header(AVFormatContext *avf)
>              FAIL(AVERROR_INVALIDDATA);
>          }
>      }
> -    if (ret < 0)
> +    if (ret != AVERROR_EOF && ret < 0)
>          goto fail;
>      if (!cat->nb_files)
>          FAIL(AVERROR_INVALIDDATA);
> @@ -499,9 +500,11 @@ static int concat_read_header(AVFormatContext *avf)
>                                                 MATCH_ONE_TO_ONE;
>      if ((ret = open_file(avf, 0)) < 0)
>          goto fail;
> +    av_bprint_finalize(&bp, NULL);
>      return 0;
>  
>  fail:
> +    av_bprint_finalize(&bp, NULL);
>      concat_read_close(avf);
>      return ret;
>  }

LGTM, thanks.

Regards,

Patch hide | download patch | download mbox

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 178fac86cb..3e41a62a36 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -24,6 +24,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timestamp.h"
+#include "libavutil/bprint.h"
 #include "avformat.h"
 #include "internal.h"
 #include "url.h"
@@ -386,18 +387,18 @@  static int concat_read_close(AVFormatContext *avf)
 static int concat_read_header(AVFormatContext *avf)
 {
     ConcatContext *cat = avf->priv_data;
-    uint8_t buf[4096];
+    AVBPrint bp;
     uint8_t *cursor, *keyword;
-    int ret, line = 0, i;
+    int line = 0, i;
     unsigned nb_files_alloc = 0;
     ConcatFile *file = NULL;
-    int64_t time = 0;
+    int64_t ret, time = 0;
 
-    while (1) {
-        if ((ret = ff_get_line(avf->pb, buf, sizeof(buf))) <= 0)
-            break;
+    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+
+    while ((ret = ff_read_line_to_bprint_overwrite(avf->pb, &bp)) >= 0) {
         line++;
-        cursor = buf;
+        cursor = bp.str;
         keyword = get_keyword(&cursor);
         if (!*keyword || *keyword == '#')
             continue;
@@ -473,7 +474,7 @@  static int concat_read_header(AVFormatContext *avf)
             FAIL(AVERROR_INVALIDDATA);
         }
     }
-    if (ret < 0)
+    if (ret != AVERROR_EOF && ret < 0)
         goto fail;
     if (!cat->nb_files)
         FAIL(AVERROR_INVALIDDATA);
@@ -499,9 +500,11 @@  static int concat_read_header(AVFormatContext *avf)
                                                MATCH_ONE_TO_ONE;
     if ((ret = open_file(avf, 0)) < 0)
         goto fail;
+    av_bprint_finalize(&bp, NULL);
     return 0;
 
 fail:
+    av_bprint_finalize(&bp, NULL);
     concat_read_close(avf);
     return ret;
 }