diff mbox series

[FFmpeg-devel,3/3] avformat/rmdec: Reorder operations to avoid overflow

Message ID 20201203091139.14038-3-michael@niedermayer.cc
State Accepted
Commit b12e713b8061cc6a71ec69da946552bc593d5fa7
Headers show
Series [FFmpeg-devel,1/3] avformat/id3v2: Sanity check tlen before alloc and uncompress | 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 Dec. 3, 2020, 9:11 a.m. UTC
Fixes: signed integer overflow: -2147483648 - 14 cannot be represented in type 'int'
Fixes: 27659/clusterfuzz-testcase-minimized-ffmpeg_dem_RM_fuzzer-5697250168406016

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/rmdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 004c62086d..a82519987c 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -719,9 +719,9 @@  static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre
                     av_log(s, AV_LOG_WARNING,
                            "Index size %d (%d pkts) is wrong, should be %"PRId64".\n",
                            len, n_pkts, expected_len);
-                len -= 14; // we already read part of the index header
-                if(len<0)
+                if(len < 14)
                     continue;
+                len -= 14; // we already read part of the index header
                 goto skip;
             } else if (state == MKBETAG('D','A','T','A')) {
                 av_log(s, AV_LOG_WARNING,