Commit 1a0f1062 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/pnm: Check magic bytes directly without pnm_get()

Fixes: Timeout (10sec -> 30ms) (case 15089)
Fixes: 15089/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PBM_fuzzer-5767535057698816
Fixes: 16001/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGM_fuzzer-5199169645445120
Fixes: 16003/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-5076443270217728

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpegSigned-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 77abf314
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
...@@ -68,9 +69,15 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -68,9 +69,15 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
int h, w, depth, maxval; int h, w, depth, maxval;
int ret; int ret;
pnm_get(s, buf1, sizeof(buf1)); if (s->bytestream_end - s->bytestream < 3 ||
if(buf1[0] != 'P') s->bytestream[0] != 'P' ||
s->bytestream[1] < '1' ||
s->bytestream[1] > '7') {
s->bytestream += s->bytestream_end > s->bytestream;
s->bytestream += s->bytestream_end > s->bytestream;
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
pnm_get(s, buf1, sizeof(buf1));
s->type= buf1[1]-'0'; s->type= buf1[1]-'0';
if (s->type==1 || s->type==4) { if (s->type==1 || s->type==4) {
...@@ -152,7 +159,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -152,7 +159,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
} }
return 0; return 0;
} else { } else {
return AVERROR_INVALIDDATA; av_assert0(0);
} }
pnm_get(s, buf1, sizeof(buf1)); pnm_get(s, buf1, sizeof(buf1));
w = atoi(buf1); w = atoi(buf1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment