diff mbox series

[FFmpeg-devel] avcodec/flac_parser: fix triggered assert

Message ID CAPYw7P7wg3NES7mvDqYxp2WzMpb_5sfCvDv+Th+etFjxcZv6DA@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/flac_parser: fix triggered assert | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Paul B Mahol Sept. 8, 2022, 4:17 p.m. UTC
Patch attached.

Comments

Paul B Mahol Sept. 13, 2022, 9:28 a.m. UTC | #1
On 9/8/22, Paul B Mahol <onemda@gmail.com> wrote:
> Patch attached.
>

Will apply soon.
Mattias Wadman Sept. 13, 2022, 4:11 p.m. UTC | #2
On Tue, Sep 13, 2022 at 11:28 AM Paul B Mahol <onemda@gmail.com> wrote:

> On 9/8/22, Paul B Mahol <onemda@gmail.com> wrote:
> > Patch attached.
> >
>
> Will apply soon.


Curious where the 1 << 28 constant come from?
diff mbox series

Patch

From a726d0a26c9f60d65167a83789f9c222cfda5728 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Thu, 8 Sep 2022 09:59:09 +0200
Subject: [PATCH] avcodec/flac_parser: avoid returning too negative number

If return value is very small parser code will assert.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/flac_parser.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index 5b3a4e6e67..bd91cc1a05 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -663,8 +663,11 @@  static int get_best_header(FLACParseContext *fpc, const uint8_t **poutbuf,
 
     /* Return the negative overread index so the client can compute pos.
        This should be the amount overread to the beginning of the child */
-    if (child)
-        return child->offset - flac_fifo_size(&fpc->fifo_buf);
+    if (child) {
+        int64_t offset = child->offset - flac_fifo_size(&fpc->fifo_buf);
+        if (offset > -(1 << 28))
+            return offset;
+    }
     return 0;
 }
 
-- 
2.37.2