diff mbox series

[FFmpeg-devel] avcodec/hapdec: Change compressed_offset to unsigned 32bit

Message ID 20210219201625.30110-1-michael@niedermayer.cc
State Accepted
Commit 89fe1935b18621af06587c76bcde6adcdc8f2249
Headers show
Series [FFmpeg-devel] avcodec/hapdec: Change compressed_offset to unsigned 32bit
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer Feb. 19, 2021, 8:16 p.m. UTC
Fixes: out of array access
Fixes: 29345/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HAP_fuzzer-5401813482340352
Fixes: 30745/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HAP_fuzzer-5762798221131776

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

Comments

Paul B Mahol Feb. 19, 2021, 8:24 p.m. UTC | #1
lgtm
Michael Niedermayer Feb. 19, 2021, 10:15 p.m. UTC | #2
On Fri, Feb 19, 2021 at 09:24:49PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index bbeed11e32..00c3dbb32d 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -52,7 +52,7 @@  enum HapSectionType {
 
 typedef struct HapChunk {
     enum HapCompressor compressor;
-    int compressed_offset;
+    uint32_t compressed_offset;
     size_t compressed_size;
     int uncompressed_offset;
     size_t uncompressed_size;
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index ab364aa790..692bb6e750 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -105,6 +105,8 @@  static int hap_parse_decode_instructions(HapContext *ctx, int size)
         size_t running_size = 0;
         for (i = 0; i < ctx->chunk_count; i++) {
             ctx->chunks[i].compressed_offset = running_size;
+            if (ctx->chunks[i].compressed_size > UINT32_MAX - running_size)
+                return AVERROR_INVALIDDATA;
             running_size += ctx->chunks[i].compressed_size;
         }
     }
@@ -186,7 +188,7 @@  static int hap_parse_frame_header(AVCodecContext *avctx)
         HapChunk *chunk = &ctx->chunks[i];
 
         /* Check the compressed buffer is valid */
-        if (chunk->compressed_offset + chunk->compressed_size > bytestream2_get_bytes_left(gbc))
+        if (chunk->compressed_offset + (uint64_t)chunk->compressed_size > bytestream2_get_bytes_left(gbc))
             return AVERROR_INVALIDDATA;
 
         /* Chunks are unpacked sequentially, ctx->tex_size is the uncompressed