From patchwork Sat Jul 28 12:32:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 9829 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp1885799jad; Sat, 28 Jul 2018 05:33:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfrtkzf9ocsR8nSfXQdw/vwJBaNNQ2xyjqocIgVwNC9xC0bpyj5P7vZTja1WmORRpaO9RFj X-Received: by 2002:a1c:4c0e:: with SMTP id z14-v6mr8446149wmf.89.1532781192977; Sat, 28 Jul 2018 05:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532781192; cv=none; d=google.com; s=arc-20160816; b=q6IourTGGP6UsVpurDoG7beo7pHvQbMtELP1lLXtc/hBz+jppqKADPNdQoPdAgcXln pyq18W8PfxGVL/Gu4NGBf2wnllpM9pqXevHgdJAOZT57OLrl3kpekwByUpJZa/aaxMMY 94nATtcwTiSYIt5kWZ62WMAxBGwsgdFjNJscJrizTu2bo4OjwvRVOygFxnjqoJjcIBDN qntJ2crM9uPiaCdsgNbYmjVENUrYItaaGOFM87zqHh71HotTKCk4qjrari5MeWpfL1Ix FAJY2TWfobgXNZvNzXO5KgAbheZJivsFuak5fhdJYC25HNvrE+5euKiXr5wzUTFLvPZW B/0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=XCAVNVWCT7jpuPxTCzpqpWLPmzRl9+ZhBDdK8biE3qc=; b=iP/ksDyV4gWYLzUyAdnaVNoE69F98bywvrDdLw2hGRuuhX118thHCGX2m5/516OD8S PpQX7qMcB36r7bKaUxvKF4BJ2d2/3qKCa+dfgmzMO9sT0eH1t9Pm2yPbvFaeZnqbEuo7 SeDyM6HHNXU6SfJYQ0bxQe7IpUs4Fqys9IiYwtvn6RMuFjRuAGbnVbQ0T8f4NoXDf1/6 nR9gDZd6foLKgyIOaUWD5u5QwV+JzHek+rj7WjY1dZlk2eKnL588O6SVB66Y5plQGA41 /gzny4d5ki2Nj+QROsrGQOohih3ZnkuvypubjyM97C4ZYC870gGh2k/h0q7ELY9d9Zt9 NQLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n4-v6si6771158wri.239.2018.07.28.05.33.12; Sat, 28 Jul 2018 05:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C2E468A362; Sat, 28 Jul 2018 15:32:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEE65680BB6 for ; Sat, 28 Jul 2018 15:32:47 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fjOP9-00066i-BB for ffmpeg-devel@ffmpeg.org; Sat, 28 Jul 2018 14:33:03 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id GCYz1y00B0S5wYM01CZ02Y; Sat, 28 Jul 2018 14:33:00 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 28 Jul 2018 14:32:32 +0200 Message-Id: <20180728123232.6191-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180728123232.6191-1-michael@niedermayer.cc> References: <20180728123232.6191-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/pnm_parser: Avoid reparsing failed data. 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Alternatively the parser could be re implemented / redesigned so as to better and more efficiently find frame boundaries Fixes: Timeout Fixes: 9210/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PBM_fuzzer-4770771833454592 Fixes: 9214/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PPM_fuzzer-5741633353023488 Fixes: 9219/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGM_fuzzer-6249230237696000 Fixes: 9550/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PAM_fuzzer-5312669836902400 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pnm_parser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c index bdd7f2b505..4bcd0ddd5d 100644 --- a/libavcodec/pnm_parser.c +++ b/libavcodec/pnm_parser.c @@ -51,8 +51,9 @@ retry: if (pc->index) { pc->index = 0; } else { - buf++; - buf_size--; + unsigned step = FFMAX(1, pnmctx.bytestream - pnmctx.bytestream_start); + buf += step; + buf_size -= step; } goto retry; }