avcodec/pnm_parser: Use memmove() to handle "overread"
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 1 Aug 2019 20:20:48 +0000 (22:20 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Fri, 23 Aug 2019 20:26:50 +0000 (22:26 +0200)
This is significantly faster

Fixes: Timeout (1sec after this and the previous commit)
Fixes: 15558/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PPM_fuzzer-5705273643106304

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 5339beb..94777d2 100644 (file)
@@ -41,8 +41,11 @@ static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx,
     int next = END_NOT_FOUND;
     int skip = 0;
 
-    for (; pc->overread > 0; pc->overread--) {
-        pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
+    if (pc->overread > 0) {
+        memmove(pc->buffer + pc->index, pc->buffer + pc->overread_index, pc->overread);
+        pc->index          += pc->overread;
+        pc->overread_index += pc->overread;
+        pc->overread = 0;
     }
 
     if (pnmpc->remaining_bytes) {