From patchwork Thu Oct 22 22:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 23161 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 BCA0644ADC3 for ; Fri, 23 Oct 2020 01:42:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6B7A68A466; Fri, 23 Oct 2020 01:42:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-2.mx.upcmail.net (vie01a-dmta-pe02-2.mx.upcmail.net [62.179.121.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5375A680B17 for ; Fri, 23 Oct 2020 01:42:14 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1kVjHh-0007NS-0N for ffmpeg-devel@ffmpeg.org; Fri, 23 Oct 2020 00:42:13 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id VjGik6FZ7Ir7GVjGikbcEj; Fri, 23 Oct 2020 00:41:13 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=QN4WuTDL c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=Z-YTeU3EeSqCZd7VZu8A:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 23 Oct 2020 00:41:08 +0200 Message-Id: <20201022224112.9071-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfNRaCT75VLYHz4IsExGwu/UEepbl/FOvBN7Sb3zUoO81InvlJaWHN1270mUvh/9kl7zl7VRFKAE7Pq9Hntc0WQHLocs2oa70qOoG6bHLB/y1Sc4KU/dE InH4S/EJ6FuBF8V5eCQANIqnAbMsB1lA0kXRYzlA5pciexms9LmOpXIs Subject: [FFmpeg-devel] [PATCH 1/5] avformat/mpegts: Limit iterations of get_packet_size() 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" This is a pathological case where the fuzzer provides only 2 bytes per iteration. Fixes: Timeout (>30 -> 0.9sec) Fixes: 26488/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTS_fuzzer-5911031077142528 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mpegts.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 3085371c58..4e5f556d94 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -609,8 +609,9 @@ static int get_packet_size(AVFormatContext* s) /*init buffer to store stream for probing */ uint8_t buf[PROBE_PACKET_MAX_BUF] = {0}; int buf_size = 0; + int max_iterations = 16; - while (buf_size < PROBE_PACKET_MAX_BUF) { + while (buf_size < PROBE_PACKET_MAX_BUF && max_iterations--) { ret = avio_read_partial(s->pb, buf + buf_size, PROBE_PACKET_MAX_BUF - buf_size); if (ret < 0) return AVERROR_INVALIDDATA;