From patchwork Sun Mar 10 23:42:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 12281 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 5D7F44488BC for ; Mon, 11 Mar 2019 01:44:07 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4705568A60D; Mon, 11 Mar 2019 01:44:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe08-3.mx.upcmail.net (vie01a-dmta-pe08-3.mx.upcmail.net [84.116.36.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C13B268A551 for ; Mon, 11 Mar 2019 01:44:00 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1h386q-00035O-3R for ffmpeg-devel@ffmpeg.org; Mon, 11 Mar 2019 00:44:00 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 385rhdQnPxLwq385rhgS7n; Mon, 11 Mar 2019 00:43:00 +0100 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=WaxylHpX c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=ovn-Sg83f6JknjqKF0oA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 11 Mar 2019 00:42:08 +0100 Message-Id: <20190310234209.9975-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfCCmJAEvFJWIim61Lj71Gpu5ayve5RghXVWC7ta84i0g+0hZFgCCiCEHW3JfUBakcVvTf7fGuU/ceNDznuiGQbxVaVchq9CuGt4k/K8v56YsfyyCImL6 ZwV5MPM3U0giayAoHf0ykynb4GN8lOCDq848mhDH5IjkWCMH9VuL4yHw Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/pnm: Optimize reading loop in 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 13149 (5sec -> 3sec), 13166 (11sec -> 7sec), 13430 (5sec -> 3sec) Fixes: 13149/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGM_fuzzer-5760833622114304 Fixes: 13166/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-5763216322330624 Fixes: 13430/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PPM_fuzzer-5758658334425088 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pnm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index 17926f256f..a9771710c2 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -52,12 +52,13 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) } s = str; - while (bs < end && !pnm_space(c)) { - if ((s - str) < buf_size - 1) - *s++ = c; + while (bs < end && !pnm_space(c) && (s - str) < buf_size - 1) { + *s++ = c; c = *bs++; } *s = '\0'; + while (bs < end && !pnm_space(c)) + c = *bs++; sc->bytestream = bs; }