diff mbox series

[FFmpeg-devel,1/3] avformat/mpc8: check for size overflow in mpc8_get_chunk_header()

Message ID 20210317231728.2130-1-michael@niedermayer.cc
State Accepted
Commit 6cc65d3d6760cfb08c5a9e57d4306d88428e18d0
Headers show
Series [FFmpeg-devel,1/3] avformat/mpc8: check for size overflow in mpc8_get_chunk_header() | expand

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 March 17, 2021, 11:17 p.m. UTC
Fixes: signed integer overflow: -9223372036854775760 - 50 cannot be represented in type 'long'
Fixes: 31673/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-580134751869337

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

Comments

Michael Niedermayer March 31, 2021, 6:47 p.m. UTC | #1
On Thu, Mar 18, 2021 at 12:17:26AM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: -9223372036854775760 - 50 cannot be represented in type 'long'
> Fixes: 31673/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-580134751869337
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/mpc8.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

will apply


[...]
diff mbox series

Patch

diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index ff7da2ef55..b12a417f63 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -127,7 +127,11 @@  static void mpc8_get_chunk_header(AVIOContext *pb, int *tag, int64_t *size)
     pos = avio_tell(pb);
     *tag = avio_rl16(pb);
     *size = ffio_read_varlen(pb);
-    *size -= avio_tell(pb) - pos;
+    pos -= avio_tell(pb);
+    if (av_sat_add64(*size, pos) != (uint64_t)*size + pos) {
+        *size = -1;
+    } else
+        *size += pos;
 }
 
 static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)