diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2021-02-19 21:16:25 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2021-10-17 21:34:53 +0200 |
commit | 59652534dda36ee88b4b684fd915318f130db8f4 (patch) | |
tree | d860e08c26551ec165da18fab8ac108de5fdeb0f | |
parent | 4f1d285001ea39299928cb2a9fb02433321c1bfd (diff) | |
download | ffmpeg-59652534dda36ee88b4b684fd915318f130db8f4.tar.gz |
avcodec/hapdec: Change compressed_offset to unsigned 32bit
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
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 89fe1935b18621af06587c76bcde6adcdc8f2249)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/hap.h | 2 | ||||
-rw-r--r-- | libavcodec/hapdec.c | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/libavcodec/hap.h b/libavcodec/hap.h index e4762ee438..7543efcf05 100644 --- a/libavcodec/hap.h +++ b/libavcodec/hap.h @@ -51,7 +51,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 6adac21bbb..0a654e2fa0 100644 --- a/libavcodec/hapdec.c +++ b/libavcodec/hapdec.c @@ -129,6 +129,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; } } @@ -207,7 +209,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 |