From patchwork Sun Sep 18 17:14:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 38005 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp791246pzh; Sun, 18 Sep 2022 10:15:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/d8qApEspH3RXOUIdFnLaBfZdET73MsCZSAyRKwDJCvsMKLMh/Qb2EBDp1gIPVfr/ig0Z X-Received: by 2002:a17:907:845:b0:731:2f6c:6dbd with SMTP id ww5-20020a170907084500b007312f6c6dbdmr10097521ejb.551.1663521347671; Sun, 18 Sep 2022 10:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663521347; cv=none; d=google.com; s=arc-20160816; b=wWw/6Fqb7IX+LOtmYvIhOJ8ZJukhmGDqqV1HpukVJoUvGXLV74UrDea1uqBIIiQZ6r +JI/ufXFNjRaEHWqYfCQtEh8HNnyGiiBUcCB3+AhZqj05EuOjoAa34poiSkWIlloxO3T rw53Oqh7s0/Cwm+w7BygdJXBxsWhsLkj7r7avcOg8m+1PTyXaCG01RTdDJu5eqxELGYc s29JArBYpxf5eSr8V+BumNLubzIfmeXMahrIiIYoMJ7nA8zZ5NzR0YaeK5yE9b1FjCRZ 5dxsu+bQ1bjePBlMqrmnEqGi+V0gZPJMnijMAdmS0QCxrKpP8WzZNJHNC/AM+dlNkT/u WihQ== 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=P+ijITAUGDkuHcfFriaRHCSduCw0Jdcol3F2R5KsQ24=; b=vNFLntxWcmKXrUh1Jg09xLKcjCdM0A3dSQCMHeefjZrK9W9ajkjUmg1eBrnL9WV+Fp TT/vt261sj5ImhyPxL23VhYHhjROUJsRlWmeKwCN/nxLHiXksOEVdFFUfjlBlc5aJI7t 4uIVPNbaiA1i7WMcNP1IyB9V2EXhcVgw4MKlCHcFcXdpBhZ/oYDBYBphOtW90AYWHyZy Ja/Ns2OhUIuFzP4paQrNCsj7FKPeXYcPNQrI++LyAuO74PmG0B5IjBVupyYGZP8AT5PQ P3uq7MmGKst//Tk+xleiugcgPdST2XcQGhbTs9yX03ZXaHqxE841XmEv/dSK2zSS7lh1 SJgA== 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 qf26-20020a1709077f1a00b0073bebc45090si19130130ejc.392.2022.09.18.10.15.47; Sun, 18 Sep 2022 10:15:47 -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 2E21268BBD5; Sun, 18 Sep 2022 20:14:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at01-3.mx.upcmail.net (vie01a-dmta-at01-3.mx.upcmail.net [62.179.121.147]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EAEBB68B96F for ; Sun, 18 Sep 2022 20:14:13 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oZxrx-00Hane-Fz for ffmpeg-devel@ffmpeg.org; Sun, 18 Sep 2022 19:14:13 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id Zxrtolzzs8s8UZxrxoH67F; Sun, 18 Sep 2022 19:14:13 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id ZxrxoprDmOG5ZZxrxonHik; Sun, 18 Sep 2022 19:14: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.4 cv=KJo5sHJo c=1 sm=1 tr=0 ts=632751e5 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=vQp9cOZCSIj9pZDBZ8kA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 18 Sep 2022 19:14:09 +0200 Message-Id: <20220918171410.31835-12-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220918171410.31835-1-michael@niedermayer.cc> References: <20220918171410.31835-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfDbd5uOikFynSxtcRSdV7B3YQPfN2yNcUeVdyOi4L3ghNI+dmAB/widXj3Yt8dy6gVCIJOfoL2QXr2T8rMztHUDDxKZvjB6j6Rpq9ZA5v9kzp1ia7DSg Wapp+4xdzDUAurop/nMq9tLLeCRI4Kx8GVkrVJPIElWgQuuy+GSfsI+B53cnSgDriDwmBX9qBzW1bg== Subject: [FFmpeg-devel] [PATCH 12/13] avformat/matroskadec: Error out if a timestamp is beyond duration 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: tk1SpXYkcT6y Maybe timestamp / duration validity should be checked earlier Fixes: 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6586894739177472 Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long' Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/matroskadec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 16a3e936110..8b079e11104 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -4009,7 +4009,8 @@ typedef struct { /* This function searches all the Cues and returns the CueDesc corresponding to * the timestamp ts. Returned CueDesc will be such that start_time_ns <= ts < - * end_time_ns. All 4 fields will be set to -1 if ts >= file's duration. + * end_time_ns. All 4 fields will be set to -1 if ts >= file's duration or + * if an error occurred. */ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) { MatroskaDemuxContext *matroska = s->priv_data; @@ -4028,6 +4029,8 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) } } --i; + if (index_entries[i].timestamp > matroska->duration) + return (CueDesc) {-1, -1, -1, -1}; cue_desc.start_time_ns = index_entries[i].timestamp * matroska->time_scale; cue_desc.start_offset = index_entries[i].pos - matroska->segment_start; if (i != nb_index_entries - 1) {