From patchwork Thu Aug 1 21:44:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14186 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7491C447E7E for ; Fri, 2 Aug 2019 00:46:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F53368ABC5; Fri, 2 Aug 2019 00:46:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe05-1.mx.upcmail.net [84.116.36.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE58868A362 for ; Fri, 2 Aug 2019 00:46:16 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1htIts-00038B-2A for ffmpeg-devel@ffmpeg.org; Thu, 01 Aug 2019 23:46:16 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id tIsthTE285D5NtIsuhm8oF; Thu, 01 Aug 2019 23:45:16 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=bu8y+3Si c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=0jEgUhlgFG1HdnktMP0A:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 1 Aug 2019 23:44:40 +0200 Message-Id: <20190801214443.7695-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190801214443.7695-1-michael@niedermayer.cc> References: <20190801214443.7695-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfNY1oT4jhzgPhWZYDp/4k/3+tPzJbvytBIjIqCinLtqaBEZF9jf9uNY2PrJWmA17sWWgJeZlFk+Lh21loH0c3IhAbc1cnOavISbZ4eRZJWw3qJ4SWEn8 A0T7tRXC8b/tx38B+NMURBpwL/g8nFAQAzzt0za6S1lth7dnoBZ+pRQJ Subject: [FFmpeg-devel] [PATCH 2/5] avcodec/pnm: Check magic bytes directly without pnm_get() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pnm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index a9771710c2..a613f13477 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -22,6 +22,7 @@ #include #include +#include "libavutil/avassert.h" #include "libavutil/imgutils.h" #include "avcodec.h" #include "internal.h" @@ -68,9 +69,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) int h, w, depth, maxval; int ret; - pnm_get(s, buf1, sizeof(buf1)); - if(buf1[0] != 'P') + if (s->bytestream_end - s->bytestream < 3 || + s->bytestream[0] != 'P' || + s->bytestream[1] < '1' || + s->bytestream[1] > '7') return AVERROR_INVALIDDATA; + pnm_get(s, buf1, sizeof(buf1)); s->type= buf1[1]-'0'; if (s->type==1 || s->type==4) { @@ -152,7 +156,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) } return 0; } else { - return AVERROR_INVALIDDATA; + av_assert0(0); } pnm_get(s, buf1, sizeof(buf1)); w = atoi(buf1);