From patchwork Tue Nov 8 20:38:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Cadhalpun X-Patchwork-Id: 1345 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1893057vsb; Tue, 8 Nov 2016 12:39:00 -0800 (PST) X-Received: by 10.28.130.66 with SMTP id e63mr10769603wmd.39.1478637540296; Tue, 08 Nov 2016 12:39:00 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k10si37338949wjy.47.2016.11.08.12.38.59; Tue, 08 Nov 2016 12:39:00 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@googlemail.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; dmarc=fail (p=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1C6B1689DD3; Tue, 8 Nov 2016 22:38:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5BDB689731 for ; Tue, 8 Nov 2016 22:38:47 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id u144so25036953wmu.0 for ; Tue, 08 Nov 2016 12:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to; bh=nor/ZE+kvzt7MIf3Hvn02LDy0S1ngxoZgemta9atlow=; b=rdEYZoEsoB6GZQgJ/7m5tkB/zHIminQeNrKECPOHaD/yWTBLm37nkfWpb/rWbzgqsk BPqOB1zOH6RAzQbMhQk+t+gBSh7LI1/zp+rFxLjpnUaOl0QurxvMSR8XLYaLxSp6IJcT ljWhUJzgUe8DRbz9v5He8GpLjJ3e/bysuBxru7s+gKCQLJ1o1Un9PxsJqLQD3uP74cOl 4O2/TCt83W01WuCPgDhjcZ/HOLAY8tA4HPkS8Hm5ymaqkUXJxndw+77dODi29F1rcyfs BCPoqAmB0/7zbQ9hKOt/mpjZoB0OfdOXczzOAoBHRJU4ksijc+Au+mUPVQ60HKKDA1ZQ w2DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to; bh=nor/ZE+kvzt7MIf3Hvn02LDy0S1ngxoZgemta9atlow=; b=Lbk/+P1KR0lQ6+CyPYEvL4GoJWDqCMPkdIQUTGKiO4DXMSxdOsCGT+ghj1/sZFv90e WOVbPUCN6hPv7X0yRcao6KZlO7jaauyp0oGeiy4WpEXApoEOV2dsnvdIN6sejzN4c0t9 xV4EYruGIRzy8yrxFnQ8LX/QrTOj97RCYdjEiOT3v7I42M8fqWim6RtNTw6sK5kAUC6o EtHzMWTelS0hUpFKbTN2CI4VABMmsJquNbK/trU3wpp7L+ZuOY9eu8e4tGkR12/OI2Zb c9e89uznlc/rgzpoqlJeM03AtCZCU6Q2yBzmzdHTEhDVVF9K5R1wSooOWiisa4XRMt4T Bgjg== X-Gm-Message-State: ABUngvcHy+k8z4sn8Cob3/yP7xu8NWFw5RC7mPSz0PdCn0v2Ijtmmc8Ao1L5QYgZFfIyKg== X-Received: by 10.28.185.78 with SMTP id j75mr16329767wmf.14.1478637530953; Tue, 08 Nov 2016 12:38:50 -0800 (PST) Received: from [192.168.2.21] (pD9E8FF48.dip0.t-ipconnect.de. [217.232.255.72]) by smtp.googlemail.com with ESMTPSA id vr9sm33136278wjc.35.2016.11.08.12.38.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Nov 2016 12:38:50 -0800 (PST) From: Andreas Cadhalpun X-Google-Original-From: Andreas Cadhalpun To: ffmpeg-devel@ffmpeg.org, libav development References: <20161107235407.GG4602@nb4> <0cf22af6-5e88-8e78-1229-22b04824874a@googlemail.com> <20161108200904.GV4602@nb4> Message-ID: <49386de7-50a4-fcc5-f956-5a3542a3d0ef@googlemail.com> Date: Tue, 8 Nov 2016 21:38:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161108200904.GV4602@nb4> Subject: Re: [FFmpeg-devel] [PATCH] mpegts: prevent division by zero 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" On 08.11.2016 21:09, Michael Niedermayer wrote: > On Tue, Nov 08, 2016 at 07:47:02PM +0100, Andreas Cadhalpun wrote: >> On 08.11.2016 00:54, Michael Niedermayer wrote: >>> On Mon, Nov 07, 2016 at 11:49:52PM +0100, Andreas Cadhalpun wrote: >>>> Signed-off-by: Andreas Cadhalpun >>>> --- >>>> libavformat/mpegts.c | 4 ++++ >>>> 1 file changed, 4 insertions(+) >>>> >>>> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c >>>> index fad10c6..77d63f2 100644 >>>> --- a/libavformat/mpegts.c >>>> +++ b/libavformat/mpegts.c >>>> @@ -2692,6 +2692,10 @@ static int mpegts_read_header(AVFormatContext *s) >>>> /* NOTE1: the bitrate is computed without the FEC */ >>>> /* NOTE2: it is only the bitrate of the start of the stream */ >>>> ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]); >>>> + if (ts->pcr_incr <= 0) { >>>> + av_log(s, AV_LOG_ERROR, "invalid pcr increment %d\n", ts->pcr_incr); >>>> + return AVERROR_INVALIDDATA; >>>> + } >>> >>> if a pcr pair is bad i would suggest to run the loop by another >>> iteration >> >> That's a good idea. New patch attached. > > LGTM, maybe add a av_log() so the user knows of the issue Makes sense, patch with added log message is attached. > (especially > if all pcr are systematically bad, n which case this would need to be > adjusted to not fail) What do you think should be done in that case? Best regards, Andreas From 02fc2ecef2adb20c3be63a6787c6921f8471ca04 Mon Sep 17 00:00:00 2001 From: Andreas Cadhalpun Date: Mon, 7 Nov 2016 23:37:59 +0100 Subject: [PATCH] mpegts: prevent division by zero Signed-off-by: Andreas Cadhalpun --- libavformat/mpegts.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index fad10c6..0aa0ad7 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2681,8 +2681,17 @@ static int mpegts_read_header(AVFormatContext *s) packet_count[nb_pcrs] = nb_packets; pcrs[nb_pcrs] = pcr_h * 300 + pcr_l; nb_pcrs++; - if (nb_pcrs >= 2) - break; + if (nb_pcrs >= 2) { + if (pcrs[1] - pcrs[0] > 0) { + /* the difference needs to be positive to make sense for bitrate computation */ + break; + } else { + av_log(ts->stream, AV_LOG_WARNING, "invalid pcr pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]); + pcrs[0] = pcrs[1]; + packet_count[0] = packet_count[1]; + nb_pcrs--; + } + } } else { finished_reading_packet(s, ts->raw_packet_size); } -- 2.10.2