[FFmpeg-devel] [PATCH 3/3] avcodec/hapdec: Check that compressed_offset is non negative

Michael Niedermayer michael at niedermayer.cc
Sat Jan 30 21:28:26 EET 2021


Fixes: out of array access
Fixes: 29345/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HAP_fuzzer-5401813482340352

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

diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index ab364aa790..260fda2968 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -86,6 +86,8 @@ static int hap_parse_decode_instructions(HapContext *ctx, int size)
                     return ret;
                 for (i = 0; i < section_size / 4; i++) {
                     ctx->chunks[i].compressed_offset = bytestream2_get_le32(gbc);
+                    if (ctx->chunks[i].compressed_offset < 0)
+                        return AVERROR_INVALIDDATA;
                 }
                 had_offsets = 1;
                 is_first_table = 0;
@@ -106,6 +108,8 @@ static int hap_parse_decode_instructions(HapContext *ctx, int size)
         for (i = 0; i < ctx->chunk_count; i++) {
             ctx->chunks[i].compressed_offset = running_size;
             running_size += ctx->chunks[i].compressed_size;
+            if (running_size > INT_MAX)
+                return AVERROR_INVALIDDATA;
         }
     }
 
-- 
2.17.1



More information about the ffmpeg-devel mailing list