From patchwork Sun Sep 30 20:45:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10523 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:ab0:73d2:0:0:0:0:0 with SMTP id m18csp937312uaq; Sun, 30 Sep 2018 13:46:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV61UPtoy/qqdfue4qDJlK7f8KxtQ/TTdoaQzfELODqX7o2DZQ8mgbp3DeG15j1XtjdODStC8 X-Received: by 2002:adf:e58e:: with SMTP id l14-v6mr4972010wrm.321.1538340361659; Sun, 30 Sep 2018 13:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538340361; cv=none; d=google.com; s=arc-20160816; b=NiN1tN0dApWXRBOYugkVcIV5QcXTPR29je0j/M+bQqD+J1nXDg8m9ffZK2UokRuY/D Km/38Fq8T2nzGA4afUwWEBtajyVuXovmoFSkapv58xqw4JawiYibOeer1Lrb28EIzUDG A4MIwH27gwxIepMlZzB4umzjXDqSBUG5nlttOF2/dLwAqMAvcjbLAkcCq7+uIWS1onHX j7Tdqh6IV4ZkT6VrcjkdQBfmpPaOMroA8WAHFWdrfChGS99XKxzNmnW6qqaUZhq4SM7Y lOvwMrnj2UzfwFPOSgUyT9eqU4tuVaJFhbqioKlIngxFUxRgMtAlOwsir6gWPA/+s+et MCnw== 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:cc: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; bh=VrGrUAEtZkXHlKCAkucOr4herbqKC8ntaYkMsd/REa8=; b=eanaOMjcQb+8esvJltxLO/V5Yf0GpodVY/jxloeyhHVjsVSGy/QPExeXdszYcgSuYZ cMgBVULA5Z462rUwksurIj+abwleKzZviuv+ldnyO9DmOQgDjDkstFeETBPFIORA6JXA REbnh6C5mfYoOTV7zPlJ5vsucsLS7XHRUnTWh1cmSfML5zAE9Gg/xeFKouC5zeYcMwGb IE5GqukLL1svLRWMa6S5Rfs1avVGgU4NrMYs0hVYWxNxhG2clF/1U7P0HmQIb9Vj0vGH vo9jOH8n195Yn7FPxs+Zgi9Yp6YcjLnRVx/Y+1E1C3Nwu7C34fVPkv0kj+AEfCDlsVYY xGuA== 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 e13-v6si2317397wrr.152.2018.09.30.13.46.01; Sun, 30 Sep 2018 13:46:01 -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 45943689F54; Sun, 30 Sep 2018 23:45:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D7C5689EB1 for ; Sun, 30 Sep 2018 23:45:10 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id AABB5E1470; Sun, 30 Sep 2018 22:45:28 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0oc1EdN2pjGl; Sun, 30 Sep 2018 22:45:28 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D02E4E1465; Sun, 30 Sep 2018 22:45:27 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Sep 2018 22:45:13 +0200 Message-Id: <20180930204513.26772-5-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180930204513.26772-1-cus@passwd.hu> References: <20180930204513.26772-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 5/5] avutil/parseutils: fix some overflows in duration calculations 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 Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also properly return AVERROR(ERANGE) in case of actual overflows. Signed-off-by: Marton Balint --- libavutil/parseutils.c | 14 ++++++++++---- tests/ref/fate/parseutils | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 924c49d52c..59bec6cc9d 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -661,12 +661,15 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) if (!q) { char *o; /* parse timestr as S+ */ - dt.tm_sec = strtol(p, &o, 10); + errno = 0; + t = strtoll(p, &o, 10); if (o == p) /* the parsing didn't succeed */ return AVERROR(EINVAL); - dt.tm_min = 0; - dt.tm_hour = 0; + if (errno == ERANGE) + return AVERROR(ERANGE); q = o; + } else { + t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; } } @@ -688,7 +691,6 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) } if (duration) { - t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; if (q[0] == 'm' && q[1] == 's') { suffix = 1000; microseconds /= 1000; @@ -734,7 +736,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) if (*q) return AVERROR(EINVAL); + if (INT64_MAX / suffix < t) + return AVERROR(ERANGE); t *= suffix; + if (INT64_MAX - microseconds < t) + return AVERROR(ERANGE); t += microseconds; *timeval = negative ? -t : t; return 0; diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils index 36db4fa8a0..bd36c9b01f 100644 --- a/tests/ref/fate/parseutils +++ b/tests/ref/fate/parseutils @@ -90,10 +90,10 @@ now -> 1331972053.200000 = 2012-03-17T08:14:13Z 42.1729 -> +42172900 -1729.42 -> -1729420000 12:34 -> +754000000 -2147483648s -> -2147483648000000 -4294967296ms -> +0 -8589934592us -> +0 -9223372036854775808us -> -1 +2147483648s -> +2147483648000000 +4294967296ms -> +4294967296000 +8589934592us -> +8589934592 +9223372036854775808us -> error Testing av_get_known_color_name() AliceBlue -> R(240) G(248) B(255) A(0)