From patchwork Sat Aug 13 21:50:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 37264 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp528385pzi; Sat, 13 Aug 2022 14:50:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR5EZyyWq8UQuE+lLDvARSLam5Ln/WH0x7bUrdO/vFQyo3gT3pYwF+yz11Fv7OPmL28zqvLE X-Received: by 2002:a17:906:4786:b0:732:fc99:cf68 with SMTP id cw6-20020a170906478600b00732fc99cf68mr6915176ejc.18.1660427458128; Sat, 13 Aug 2022 14:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660427458; cv=none; d=google.com; s=arc-20160816; b=Bl9xtXVlaForSUTL/CSGJbKX37KfcIPvh0GA+RsAHlGpX8ruIV8842D8MyznYhz2gk OTquqWgWFm+L6O/RU0G71OBymU2OOgY5b5a8MCwxSpc5yYZYqG3aiuh7r7fKLjYk6wgB mRH+ytb8cQIsk2+eqoCAyGyNskj+vrY+zI7ovYU+iBjsoGZaFkFm8F6re2HFPUBEt9Yk 2z7Zi55lqrQcun2WQV5Uy3Pzl7XiPTxE7ZeXXLROvJswCxTDs3eb/RPzjt094JmOGN+R CtUu/Ssuo6xHtUqecY+7+XNW2EsF/QShgEAR/SnKPMm9AbuW5/NrVexdq5J7n/ijPQXf ZjJA== 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; bh=a2oHDN5xj9FzuzL3YfoBsC3DVuxC+r993Ywcf30uGjs=; b=K547jci1t2IVe5Oo+qEiWtfRi86bbzfJu0e00GjPP/mJFM9Oyb0J3BeKMb+g1SAZpv DmvHo8WZhiajijYLutqlxq/E6TQwHV5IQrgLw6YAchl4Em5JN868hRTnGhjIj+02T1Qb 0PdW5SYmjK9on23rwFY92CRLc1ymxf2D+JNeoeMimQuZsJIl0p4ak9JKvJaMRyL0eqmR SjU5bpQOWcnSGg+O1F2A+sGl3he3GvNbkhZGlWOx7nYWgpsYa6abfZsFI78vvJUDsqqX KUu1oiQ55kYSDAjFHs/XJe0SYw76v+X4gofAFaiXb5SCqpLvI76hfBESD6d181T4EGyE Iahg== 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 h21-20020a170906111500b007307ca55581si4014665eja.47.2022.08.13.14.50.57; Sat, 13 Aug 2022 14:50:58 -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 46B8568B178; Sun, 14 Aug 2022 00:50:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at03-2.mx.upcmail.net (vie01a-dmta-at03-2.mx.upcmail.net [62.179.121.152]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B117F68B773 for ; Sun, 14 Aug 2022 00:50:37 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oMz1h-00ANSi-Ac for ffmpeg-devel@ffmpeg.org; Sat, 13 Aug 2022 23:50:37 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id Mz1hoAgFt8s8UMz1hoTSHE; Sat, 13 Aug 2022 23:50:37 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id Mz1hoRcGOOPqFMz1hoJ2OO; Sat, 13 Aug 2022 23:50:37 +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.4 cv=OcX7sjfY c=1 sm=1 tr=0 ts=62f81cad a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=t1K1_VIw38opuqVvRWgA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 13 Aug 2022 23:50:34 +0200 Message-Id: <20220813215035.12996-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220813215035.12996-1-michael@niedermayer.cc> References: <20220813215035.12996-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfCUCXkZkzbZ+YvyIktfCLTKhPyak9dFVaBPzbrG5oCaHQdDE6Pfxi9cNzJVRTOdd8jjTTn66VdsoICkamXc/SSE643eFneuofJvIB0JCdAl3aR3aqEnl X3Dyb3yZT4aSyKF+099RE3VVJReBjNB542X4nz9U/BoqITalNm7Pewfn6K/N3nksw2HA5cSMF8BmLg== Subject: [FFmpeg-devel] [PATCH 4/5] avformat/subviewerdec: Make read_ts() more flexible X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: hmTaidCuArPN Fixes: signed integer overflow: -1948269928 * 10 cannot be represented in type 'int' Fixes: 49451/clusterfuzz-testcase-minimized-ffmpeg_dem_SUBVIEWER_fuzzer-6344614822412288 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg --- libavformat/subviewerdec.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/libavformat/subviewerdec.c b/libavformat/subviewerdec.c index e3a950fce3..6ffdc98c39 100644 --- a/libavformat/subviewerdec.c +++ b/libavformat/subviewerdec.c @@ -50,26 +50,32 @@ static int subviewer_probe(const AVProbeData *p) return 0; } +static int get_multiplier(int e) { + switch (e) { + case 1 : return 100; + case 2 : return 10; + case 3 : return 1; + default : return -1; + } +} + static int read_ts(const char *s, int64_t *start, int *duration) { int64_t end; int hh1, mm1, ss1, ms1; int hh2, mm2, ss2, ms2; - int multiplier = 1; - - if (sscanf(s, "%u:%u:%u.%2u,%u:%u:%u.%2u", - &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { - multiplier = 10; - } else if (sscanf(s, "%u:%u:%u.%1u,%u:%u:%u.%1u", - &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { - multiplier = 100; - } - if (sscanf(s, "%u:%u:%u.%u,%u:%u:%u.%u", - &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { - ms1 = FFMIN(ms1, 999); - ms2 = FFMIN(ms2, 999); - end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2 * multiplier; - *start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1 * multiplier; + int multiplier1, multiplier2; + int ms1p1, ms1p2, ms2p1, ms2p2; + + if (sscanf(s, "%u:%u:%u.%n%u%n,%u:%u:%u.%n%u%n", + &hh1, &mm1, &ss1, &ms1p1, &ms1, &ms1p2, &hh2, &mm2, &ss2, &ms2p1, &ms2, &ms2p2) == 8) { + multiplier1 = get_multiplier(ms1p2 - ms1p1); + multiplier2 = get_multiplier(ms2p2 - ms2p1); + if (multiplier1 <= 0 ||multiplier2 <= 0) + return -1; + + end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2 * multiplier2; + *start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1 * multiplier1; *duration = end - *start; return 0; }