diff mbox series

[FFmpeg-devel,1/4] avcodec/pnm_parser: Check av_image_get_buffer_size() for failure

Message ID 20210211211715.6234-1-michael@niedermayer.cc
State Accepted
Commit 5314a4996cc76e2a8534c74a66f5181e95ac64fc
Headers show
Series [FFmpeg-devel,1/4] avcodec/pnm_parser: Check av_image_get_buffer_size() for failure | 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 Feb. 11, 2021, 9:17 p.m. UTC
Fixes: out of array access
Fixes: 30135/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PBM_fuzzer-4997145650397184

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

Comments

Paul B Mahol Feb. 11, 2021, 9:27 p.m. UTC | #1
lgtm
Michael Niedermayer Feb. 11, 2021, 9:49 p.m. UTC | #2
On Thu, Feb 11, 2021 at 10:27:58PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index d19dbfe98c..f3be6d640c 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -109,8 +109,10 @@  retry:
         if (next == END_NOT_FOUND)
             pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;
     } else {
-        next = pnmctx.bytestream - pnmctx.bytestream_start + skip
-               + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+        int ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+        next = pnmctx.bytestream - pnmctx.bytestream_start + skip;
+        if (ret >= 0)
+            next += ret;
     }
     if (next != END_NOT_FOUND && pnmctx.bytestream_start != buf + skip)
         next -= pc->index;