From patchwork Sat Apr 24 15:59:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27258 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp2202507yba; Sat, 24 Apr 2021 09:00:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoh5eOsaauRxfCJ22rVIHIVHrVjLUeWnZuz1E0dMiyBUCqc+OIRuFYBw+1WlRLviXOrkom X-Received: by 2002:a05:6402:42c9:: with SMTP id i9mr11054700edc.35.1619280058192; Sat, 24 Apr 2021 09:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619280058; cv=none; d=google.com; s=arc-20160816; b=OdUufCuhv4J5+gOyhTwiTVEx3MQWqpCv/5U+174kcbtyUTrCKqZKNPFKAePps4tHO3 IyRwZbrVF8MeRJJ6BJU3HEPMJJnPW6IVDCfcxbZ7fht/6hpT17KJoGl3vb0NCPIfc8yk KvayfwT4wRjdgKjIZn6xwkfFnxQyGITY4MCFISaqJTCs6E0vIRRjbeVJxuu/dDsXQNwX dV61TLFALV3UL1/z9jOqLxLm+ck5LKM9IlRR0mGF5WDrp+kLZ2rBZ29O5eKHt2soNEmN SkWEAFlLeBIOQhsFIt/kbOTI01bOyNN9u6rwlzz27BPofIXRr73JQzw8EbfUp+UDNiZY joHQ== 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=tUt77KrniNh1U4PC4f1t+YDtQWqVSKeZx4r9sy+zmt0=; b=c2tNDOMhEzlVrKOrbWSLuZL6TM5hfdOI0M3kuUmqKdmcr5jMjIiMxI1ttvziTU6DOH 7EEgzCwfRV7H1vyzB97R1zE/Ci1eRN9ln/mmDP/auaysYCER8XWpOpJEvXRVrx0dvLq4 /grIeqqskMa4v8N8Mqk/sKWbvvM6SrjbaxuYQlzM17jBRL6l6eClcuZSFxjtNcR+u0rw Yhv5VfLmwBkM8xkKXckQ0MiC9eOU3xQu6zI2p3EYaY7LlXp+DaHy4qWKwLNq3ms6r6fT YpYJ5NByHSUVeD0i/tJYmInXakCVSyZB1jy6oysbdc4WlWpVUYrzbCSkDFXT+4AlpQzP yh7g== 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 re28si8460784ejb.40.2021.04.24.09.00.57; Sat, 24 Apr 2021 09:00: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 0F652680C00; Sat, 24 Apr 2021 19:00:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-3.mx.upcmail.net (vie01a-dmta-pe03-3.mx.upcmail.net [62.179.121.162]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67790680A7F for ; Sat, 24 Apr 2021 19:00:27 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1laKhn-007aQZ-0J for ffmpeg-devel@ffmpeg.org; Sat, 24 Apr 2021 18:00:27 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id aKgplhTQiljeHaKgpljNC2; Sat, 24 Apr 2021 17:59:27 +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.3 cv=BoHjPrf5 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=nZOtpAppAAAA:20 a=u7BG1PBdFN7e--klMW0A:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 24 Apr 2021 17:59:26 +0200 Message-Id: <20210424155926.4018-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210424155926.4018-1-michael@niedermayer.cc> References: <20210424155926.4018-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfPZ3Z1/d1B1RjEyEHujd6P/DZT81a7mZRRLm8iPdr/XjDAcFwJPxAhqMct/di+mLV6hpy1Kt74DthEXZ49p/e0LU5kM2DFWFiIl4/iaQ47N9Cwp0LBVg UC0gzUhKxq1r8rzOvOl3kqgdNGtHNn8W0xz1OjJl+RbbJHgv+zW5gwD8 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/mpc8: Check for position overflow in mpc8_handle_chunk() 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: ZR77NHcnW0+b Content-Length: 1388 Fixes: signed integer overflow: 15 + 9223372036854775796 cannot be represented in type 'long' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-6723520756318208 Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-6739833034768384 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mpc8.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index b12a417f63..b3fcae75fb 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -205,8 +205,11 @@ static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, in switch(tag){ case TAG_SEEKTBLOFF: - pos = avio_tell(pb) + size; + pos = avio_tell(pb); off = ffio_read_varlen(pb); + if (pos > INT64_MAX - size || off < 0 || off > INT64_MAX - chunk_pos) + return; + pos += size; mpc8_parse_seektable(s, chunk_pos + off); avio_seek(pb, pos, SEEK_SET); break;