From patchwork Sat Dec 4 21:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 31970 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2480220iog; Sat, 4 Dec 2021 13:34:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHz7PBWWz1dlYaceJ1xHlHw2G/fDrJe920PnfgyB7NRoYBSjCk3quFZhHtk03l8FZq1DEI X-Received: by 2002:a17:907:1deb:: with SMTP id og43mr33405454ejc.189.1638653678995; Sat, 04 Dec 2021 13:34:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638653678; cv=none; d=google.com; s=arc-20160816; b=Yn87F1JSpEKg/VmJgh8JvsSaVcheMS44nYviivNQIT+u+tG84aVh2kk+bLz+2ftSYa aCn+OOsIElRBvTt8CMBm8y8OBaCOZ6hATE48j5ySHg7haMU0EKo7DKe+/yAIKk7f3RhB 7luWs0IqsVKdrtN9rmTz7Hg4nvFYh4Zhzg3jkVsoL8fYddOyvff+kaFfXDg9dv9DHzSy VJaNTIJODrPp6wsohstsOcSXLZACpCO3/XdXJHJYpT44Etb4Dd4bd7DiAt9/BEVFA3jx ELu2y2Pb+uhN/wWpwZIb8MqfU+rrSMFJzGsTT1RtB/N1mGbQRgzxxj8L8OdS6gp8OPOb Ge+g== 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=FqFreQSEObiRK8Ta/UM2uv7eHvX4ArVcZxGkD/R3ffk=; b=Kat3gTuGm0V6hTWuLrZ/w5D1uo0tx1Hl5CoKGVXRdUeB2dV1IVXnYGK+eQ2cEp/Btw Gd5CTRI0BCXzk217iUOwFAVQrngB/BRRkYxL66rPCqhkJjN2N98xcWZM+nATenYgpt4V 1sKuCKO9K4OJcBoiLMddhu0lWTnmoy20kqAO1UFi+Z99za6rLlv/gjR5NB1DE3qEiR7X rtsDNVyACHulYKO+b4SxunIYcEVQa+xQLiMc+vWsBxmusHU9YP25JQTNIbttj2/8CI8W PYAB1njcjw3g3qfWwFhuqMsXuQcpsesCuJaeR8BimEm4CJkyQRwdj98JzDtA7KZX5p3B L41w== 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 h23si9396391edw.73.2021.12.04.13.34.38; Sat, 04 Dec 2021 13:34:38 -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; 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 7727268AE46; Sat, 4 Dec 2021 23:34:09 +0200 (EET) 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 C4F8A68A1A7 for ; Sat, 4 Dec 2021 23:34:00 +0200 (EET) 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 1mtcfQ-0001z7-0K for ffmpeg-devel@ffmpeg.org; Sat, 04 Dec 2021 22:34:00 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id tceRmpEWvSgGFtceSm7zo7; Sat, 04 Dec 2021 22:33:00 +0100 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=f8Q2+96M 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=NEAV23lmAAAA:8 a=TIUdAYB9DNzxEfSAvAsA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 4 Dec 2021 22:32:58 +0100 Message-Id: <20211204213258.11971-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211204213258.11971-1-michael@niedermayer.cc> References: <20211204213258.11971-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfA+RbEw2y3uQsc0KxJhaU/nIrwGnLzTv44W8kIpqzX/11dhFGqz8syyLhqDxi2/nup28nvLh6HaPCRbPbWFVaJTqGtqRhv4C7fvxboeqdSFeezMwO6wo PBpwW+c9zpk5H5vNiKkyFx83ySZ3bxOysB+oB9sHCegMjcSI9DHyF3JT Subject: [FFmpeg-devel] [PATCH 4/4] avformat/mov: Check next offset in mov_read_dref() 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: IceLUL0wPXd4 Fixes: signed integer overflow: 9223372036200463215 + 1109914409 cannot be represented in type 'long' Fixes: 41480/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-6553086177443840 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index ff5a55d0e62..869ff1c7c43 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -610,11 +610,13 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i = 0; i < entries; i++) { MOVDref *dref = &sc->drefs[i]; uint32_t size = avio_rb32(pb); - int64_t next = avio_tell(pb) + size - 4; + int64_t next = avio_tell(pb); - if (size < 12) + if (size < 12 || next < 0 || next > INT64_MAX - size) return AVERROR_INVALIDDATA; + next += size - 4; + dref->type = avio_rl32(pb); avio_rb32(pb); // version + flags