diff mbox series

[FFmpeg-devel,2/2] avcodec/jpeg2000dec: Check remaining data in packed_headers_stream before use

Message ID 20200801232323.8962-2-michael@niedermayer.cc
State Accepted
Commit a5ac81952e8ea3b071190d36a41b7bab4e957f66
Headers show
Series [FFmpeg-devel,1/2] avformat/mov: Check comp_brand_size
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer Aug. 1, 2020, 11:23 p.m. UTC
Fixes: out of array read
Fixes: 24487/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5165847820369920

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

Comments

Michael Niedermayer Aug. 10, 2020, 12:56 p.m. UTC | #1
On Sun, Aug 02, 2020 at 01:23:23AM +0200, Michael Niedermayer wrote:
> Fixes: out of array read
> Fixes: 24487/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5165847820369920
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/jpeg2000dec.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

will apply

[...]
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 06ad841934..dcebe97272 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -2184,7 +2184,9 @@  static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
             }
 
             if (s->has_ppm) {
-                uint32_t tp_header_size = bytestream2_get_be32u(&s->packed_headers_stream);
+                uint32_t tp_header_size = bytestream2_get_be32(&s->packed_headers_stream);
+                if (bytestream2_get_bytes_left(&s->packed_headers_stream) < tp_header_size)
+                    return AVERROR_INVALIDDATA;
                 bytestream2_init(&tp->header_tpg, s->packed_headers_stream.buffer, tp_header_size);
                 bytestream2_skip(&s->packed_headers_stream, tp_header_size);
             }