[FFmpeg-cvslog] avcodec/pnm_parser: Use memchr() in pnm_parse()

Michael Niedermayer git at videolan.org
Tue Sep 10 18:23:23 EEST 2019


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue Sep 10 00:04:08 2019 +0200| [10ea6c3116f95fc7f79d268ee2b839eea477337c] | committer: Michael Niedermayer

avcodec/pnm_parser: Use memchr() in pnm_parse()

Fixes: Timeout (45sec -> 0.5sec)
Fixes: 16942/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PPM_fuzzer-5085393073995776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=10ea6c3116f95fc7f79d268ee2b839eea477337c
---

 libavcodec/pnm_parser.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index 94777d2cca..d19dbfe98c 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -95,8 +95,11 @@ retry:
             sync = bs;
             c = *bs++;
             if (c == '#')  {
-                while (c != '\n' && bs < end)
-                    c = *bs++;
+                uint8_t *match = memchr(bs, '\n', end-bs);
+                if (match)
+                    bs = match + 1;
+                else
+                    break;
             } else if (c == 'P') {
                 next = bs - pnmctx.bytestream_start + skip - 1;
                 pnmpc->ascii_scan = 0;



More information about the ffmpeg-cvslog mailing list