[FFmpeg-devel,2/3] oavcodec/diracdec: Propagate errors from dirac_get_arith_uint()

Submitted by Michael Niedermayer on Jan. 9, 2019, 12:01 a.m.

Details

Message ID 20190109000122.17610-2-michael@niedermayer.cc
State Accepted
Commit 6ed3d0e01c20aba7ef3984c0b8965d26e9f4990c
Headers show

Commit Message

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

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 | 2 ++
 libavcodec/diracdec.c    | 2 ++
 3 files changed, 5 insertions(+)

Comments

Michael Niedermayer Jan. 15, 2019, 10:40 p.m.
On Wed, Jan 09, 2019 at 01:01:21AM +0100, Michael Niedermayer wrote:
> Testcase: 11663/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5636791864918016
> 
> 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 | 2 ++
>  libavcodec/diracdec.c    | 2 ++
>  3 files changed, 5 insertions(+)

will apply

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/dirac_arith.c b/libavcodec/dirac_arith.c
index 7eb9bd60b2..1e6b964772 100644
--- a/libavcodec/dirac_arith.c
+++ b/libavcodec/dirac_arith.c
@@ -115,6 +115,7 @@  void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
 
     c->counter = -16;
     c->range   = 0xffff;
+    c->error   = 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 24a7ca390e..efe30b79de 100644
--- a/libavcodec/dirac_arith.h
+++ b/libavcodec/dirac_arith.h
@@ -81,6 +81,7 @@  typedef struct {
     const uint8_t *bytestream_end;
 
     uint16_t contexts[DIRAC_CTX_COUNT];
+    int error;
 } DiracArith;
 
 extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT];
@@ -173,6 +174,7 @@  static inline int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_c
     while (!dirac_get_arith_bit(c, follow_ctx)) {
         if (ret >= 0x40000000) {
             av_log(NULL, AV_LOG_ERROR, "dirac_get_arith_uint overflow\n");
+            c->error = AVERROR_INVALIDDATA;
             return -1;
         }
         ret <<= 1;
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index fd23139062..db010b49cf 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -537,6 +537,8 @@  static inline int codeblock(DiracContext *s, SubBand *b,
     buf = b->ibuf + top * b->stride;
     if (is_arith) {
         for (y = top; y < bottom; y++) {
+            if (c->error)
+                return c->error;
             for (x = left; x < right; x++) {
                 if (b->pshift) {
                     coeff_unpack_arith_10(c, qfactor, qoffset, b, (int32_t*)(buf)+x, x, y);