]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/pnm_parser: Support concatenated ASCII images
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 6 Apr 2019 11:11:10 +0000 (13:11 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 10 Apr 2019 20:26:30 +0000 (22:26 +0200)
Fixes: Timeout (8sec -> 0.1sec)
Fixes: 13864/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PAM_fuzzer-5737860621139968
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

index 9bf1fdcece4873a23d48fa0fc6ce0c998b06f560..e3bfa3c490fd190658de33cd857e74bd367670bd 100644 (file)
@@ -60,7 +60,22 @@ retry:
         }
         next = END_NOT_FOUND;
     } else if (pnmctx.type < 4) {
+              uint8_t *bs  = pnmctx.bytestream;
+        const uint8_t *end = pnmctx.bytestream_end;
+
         next = END_NOT_FOUND;
+        while (bs < end) {
+            int c = *bs++;
+            if (c == '#')  {
+                while (c != '\n' && bs < end)
+                    c = *bs++;
+            } else if (c == 'P') {
+                next = bs - pnmctx.bytestream_start + skip - 1;
+                if (pnmctx.bytestream_start != buf + skip)
+                    next -= pc->index;
+                break;
+            }
+        }
     } else {
         next = pnmctx.bytestream - pnmctx.bytestream_start + skip
                + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);