avcodec/pnm: Check scale
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 6 Jun 2020 15:50:21 +0000 (17:50 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 8 Jun 2020 18:45:56 +0000 (20:45 +0200)
Fixes: division by zero
Fixes: 22974/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PFM_fuzzer-6270027077779456

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.c

index a6ae01b..aad23c7 100644 (file)
@@ -179,7 +179,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
 
     if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32) {
         pnm_get(s, buf1, sizeof(buf1));
-        if (av_sscanf(buf1, "%f", &s->scale) != 1) {
+        if (av_sscanf(buf1, "%f", &s->scale) != 1 || s->scale == 0.0 || !isfinite(s->scale)) {
             av_log(avctx, AV_LOG_ERROR, "Invalid scale.\n");
             return AVERROR_INVALIDDATA;
         }