diff mbox

[FFmpeg-devel,3/3] avcodec/dirac_arith: Treat overread as error

Message ID 20190109000122.17610-3-michael@niedermayer.cc
State Accepted
Commit 51978aefe8074cc3e020994f6b329387b2149cb8
Headers show

Commit Message

Michael Niedermayer Jan. 9, 2019, 12:01 a.m. UTC
Fixes: Timeout
Fixes: 11663/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016

Before:Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 26006 ms
After: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 106 ms

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/dirac_arith.c | 1 +
 libavcodec/dirac_arith.h | 4 ++++
 2 files changed, 5 insertions(+)

Comments

Michael Niedermayer Jan. 15, 2019, 10:40 p.m. UTC | #1
On Wed, Jan 09, 2019 at 01:01:22AM +0100, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 11663/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016
> 
> Before:Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 26006 ms
> After: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016 in 106 ms
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/dirac_arith.c | 1 +
>  libavcodec/dirac_arith.h | 4 ++++
>  2 files changed, 5 insertions(+)

will apply

[...]
diff mbox

Patch

diff --git a/libavcodec/dirac_arith.c b/libavcodec/dirac_arith.c
index 1e6b964772..36142fe198 100644
--- a/libavcodec/dirac_arith.c
+++ b/libavcodec/dirac_arith.c
@@ -116,6 +116,7 @@  void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
     c->counter = -16;
     c->range   = 0xffff;
     c->error   = 0;
+    c->overread= 0;
 
     for (i = 0; i < DIRAC_CTX_COUNT; i++)
         c->contexts[i] = 0x8000;
diff --git a/libavcodec/dirac_arith.h b/libavcodec/dirac_arith.h
index efe30b79de..79526a7ca3 100644
--- a/libavcodec/dirac_arith.h
+++ b/libavcodec/dirac_arith.h
@@ -82,6 +82,7 @@  typedef struct {
 
     uint16_t contexts[DIRAC_CTX_COUNT];
     int error;
+    int overread;
 } DiracArith;
 
 extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT];
@@ -119,6 +120,9 @@  static inline void refill(DiracArith *c)
                 new |= 0xff00;
 
             c->bytestream = c->bytestream_end;
+            c->overread ++;
+            if (c->overread > 4)
+                c->error = AVERROR_INVALIDDATA;
         }
 
         c->low += new << counter;