diff mbox series

[FFmpeg-devel,4/8] avformat/paf: Check for EOF in read_table()

Message ID 20201024222312.5806-4-michael@niedermayer.cc
State Accepted
Commit 437b7302b09a04e0fbfcd594114b52c5c6d89d32
Headers show
Series [FFmpeg-devel,1/8] tools/target_dem_fuzzer: Limit max blocks | expand

Checks

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

Commit Message

Michael Niedermayer Oct. 24, 2020, 10:23 p.m. UTC
Fixes: OOM
Fixes: 26528/clusterfuzz-testcase-minimized-ffmpeg_dem_PAF_fuzzer-5081929248145408

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

Comments

Michael Niedermayer Nov. 4, 2020, 10:40 p.m. UTC | #1
On Sun, Oct 25, 2020 at 12:23:08AM +0200, Michael Niedermayer wrote:
> Fixes: OOM
> Fixes: 26528/clusterfuzz-testcase-minimized-ffmpeg_dem_PAF_fuzzer-5081929248145408
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/paf.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)

will apply

[...]
diff mbox series

Patch

diff --git a/libavformat/paf.c b/libavformat/paf.c
index a31d01502b..9587111643 100644
--- a/libavformat/paf.c
+++ b/libavformat/paf.c
@@ -75,14 +75,18 @@  static int read_close(AVFormatContext *s)
     return 0;
 }
 
-static void read_table(AVFormatContext *s, uint32_t *table, uint32_t count)
+static int read_table(AVFormatContext *s, uint32_t *table, uint32_t count)
 {
     int i;
 
-    for (i = 0; i < count; i++)
+    for (i = 0; i < count; i++) {
+        if (avio_feof(s->pb))
+            return AVERROR_INVALIDDATA;
         table[i] = avio_rl32(s->pb);
+    }
 
     avio_skip(s->pb, 4 * (FFALIGN(count, 512) - count));
+    return 0;
 }
 
 static int read_header(AVFormatContext *s)
@@ -171,9 +175,15 @@  static int read_header(AVFormatContext *s)
 
     avio_seek(pb, p->buffer_size, SEEK_SET);
 
-    read_table(s, p->blocks_count_table,  p->nb_frames);
-    read_table(s, p->frames_offset_table, p->nb_frames);
-    read_table(s, p->blocks_offset_table, p->frame_blks);
+    ret = read_table(s, p->blocks_count_table,  p->nb_frames);
+    if (ret < 0)
+        goto fail;
+    ret = read_table(s, p->frames_offset_table, p->nb_frames);
+    if (ret < 0)
+        goto fail;
+    ret = read_table(s, p->blocks_offset_table, p->frame_blks);
+    if (ret < 0)
+        goto fail;
 
     p->got_audio = 0;
     p->current_frame = 0;