diff mbox

[FFmpeg-devel] avcodec/tak_parser: don't return error values

Message ID 20190717223850.6773-1-jamrial@gmail.com
State Superseded
Headers show

Commit Message

James Almer July 17, 2019, 10:38 p.m. UTC
The API does not allow it.

Also set poutbuf and poutbuf_size to NULL/0 on error to avoid leaving
them uninitialized.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/tak_parser.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Michael Niedermayer July 18, 2019, 10:10 p.m. UTC | #1
On Wed, Jul 17, 2019 at 07:38:50PM -0300, James Almer wrote:
> The API does not allow it.
> 
> Also set poutbuf and poutbuf_size to NULL/0 on error to avoid leaving
> them uninitialized.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/tak_parser.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/tak_parser.c b/libavcodec/tak_parser.c
> index 835a47bd52..7943d2ed3a 100644
> --- a/libavcodec/tak_parser.c
> +++ b/libavcodec/tak_parser.c
> @@ -49,7 +49,7 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
>      if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
>          TAKStreamInfo ti;
>          if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
> -            return ret;
> +            goto fail;
>          if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
>              s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
>                                                     : t->ti.frame_samples;

this would occur if buf_size is too big ( >250mb )

[...]
> +fail:
> +
> +    *poutbuf      = NULL;
> +    *poutbuf_size = 0;
> +    return buf_size + consumed;

and this would silently drop the data

i think thats not ideal, it would be better to pass through packets
which exceed the capabilities of the parser

Thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/tak_parser.c b/libavcodec/tak_parser.c
index 835a47bd52..7943d2ed3a 100644
--- a/libavcodec/tak_parser.c
+++ b/libavcodec/tak_parser.c
@@ -49,7 +49,7 @@  static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
     if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         TAKStreamInfo ti;
         if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
-            return ret;
+            goto fail;
         if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
             s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
                                                    : t->ti.frame_samples;
@@ -65,7 +65,7 @@  static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
             const uint8_t *tmp_buf = buf;
 
             if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1)
-                return AVERROR(ENOMEM);
+                goto fail;
             consumed += tmp_buf_size;
             buf      += tmp_buf_size;
             buf_size -= tmp_buf_size;
@@ -78,7 +78,7 @@  static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
 
                 if ((ret = init_get_bits8(&gb, pc->buffer + t->index,
                                           pc->index - t->index)) < 0)
-                    return ret;
+                    goto fail;
                 if (!ff_tak_decode_frame_header(avctx, &gb,
                         pc->frame_start_found ? &ti : &t->ti, 127) &&
                     !ff_tak_check_crc(pc->buffer + t->index,
@@ -103,9 +103,7 @@  found:
 
     if (consumed && !buf_size && next == END_NOT_FOUND ||
         ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
-        *poutbuf      = NULL;
-        *poutbuf_size = 0;
-        return buf_size + consumed;
+        goto fail;
     }
 
     if (next != END_NOT_FOUND) {
@@ -116,6 +114,12 @@  found:
     *poutbuf      = buf;
     *poutbuf_size = buf_size;
     return next;
+
+fail:
+
+    *poutbuf      = NULL;
+    *poutbuf_size = 0;
+    return buf_size + consumed;
 }
 
 AVCodecParser ff_tak_parser = {