diff mbox

[FFmpeg-devel] avcodec/pnm_parser: Support concatenated ASCII images

Message ID 20190406123925.17076-1-michael@niedermayer.cc
State Accepted
Commit 7f3d39b21f893145dcfd33abf6f6a2c994b246ec
Headers show

Commit Message

Michael Niedermayer April 6, 2019, 12:39 p.m. UTC
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 | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Michael Niedermayer April 10, 2019, 8:33 p.m. UTC | #1
On Sat, Apr 06, 2019 at 02:39:25PM +0200, Michael Niedermayer wrote:
> 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 | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

will apply

[...]
Carl Eugen Hoyos April 27, 2019, 11:05 a.m. UTC | #2
2019-04-06 14:39 GMT+02:00, Michael Niedermayer <michael@niedermayer.cc>:
> Fixes: Timeout (8sec -> 0.1sec)

As reported by Michael Koch, this caused a slowdown (~400x) for
the "Samsung" sample in https://trac.ffmpeg.org/wiki/RemapFilter

Carl Eugen
diff mbox

Patch

diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index 9bf1fdcece..e3bfa3c490 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -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);