From patchwork Tue Apr 27 19:21:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27439 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6109:0:0:0:0:0 with SMTP id v9csp1238890iob; Tue, 27 Apr 2021 12:23:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypO77R31YocOtBoZVAjQ4QvAHgZHM3/E2279Tx+8hA3k/PCFZuqtJpVqW2tXzk/rHHNAn9 X-Received: by 2002:aa7:d5c7:: with SMTP id d7mr6424190eds.114.1619551389858; Tue, 27 Apr 2021 12:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619551389; cv=none; d=google.com; s=arc-20160816; b=PbaCAkfxri/bsRjucak797vpdGmY0AQgI/Kjsa12XtrhR4LcAuoASty1Ml+sWf1L/H vppf8tKNWdcrgZP2fHWPbzrJWqG9ZBpEAwGKBDWZSN1Q1TRkfwFZyI5igkfwYwS5YMor cUBII297KMBk42QGDcG7WmH+E96Fx5b9/cxHmNb0ghBx8rAIpe4jOepZYKF6h6jUtO64 C3zn/pHrfRTu4p2WqFMOvIG/3sibztk35ucrE2A5OjpK0VhsbeLXSIWsqK63W538u53V 3VqeX6OUuyYwBgJ8N2PS+eivVqCp66CQxP7ZuBCbal/21PqlGP/FUyvzfklaXq6hvlWN DwFg== 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:message-id:date:to:from:delivered-to; bh=zpqEy+pAK851BHD5wrMeGtZP6Vxpg9hmIhH/vfxgX60=; b=gXpOm2xIU7P3r9J7RQ4lgYlp4/ABC1/BV/43CYygg3cAyNXA/edq+5fddit/WHm6qr SUZbSQT9FhJkEJLwE0+0+a382Z7zBM27KSgihR5xyasHmXi8siLF/YOps8+h8KHj8GFQ IuQdcMKRtB8DtgHBwWDRCznd7oxK+cTWQZCJ4Hn7IOeTgkEpNdmF63ttgDkrEwVB5iRP K10kajWZmG7jMH1oww1ifqGzoP8YMe98bZSsWGFEkAmt74UNT4f0r2JaNB0OFz2uUaVU 41JVY1P07pIDD5dM4/mUt095dqlt11kq975x/HzwHtnqnBMB8gA3C7k/pMwOSiAJf1Fk WdVg== 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 b19si3160183edr.172.2021.04.27.12.23.09; Tue, 27 Apr 2021 12:23:09 -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 ED1BB6800D8; Tue, 27 Apr 2021 22:22:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 301F2689AEE for ; Tue, 27 Apr 2021 22:22:36 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1lbTI4-009mBB-0A for ffmpeg-devel@ffmpeg.org; Tue, 27 Apr 2021 21:22:36 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id bTH5lEuPlljeHbTH5lFofZ; Tue, 27 Apr 2021 21:21:36 +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=CCrLDihfrumrGUE05UcA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 27 Apr 2021 21:21:32 +0200 Message-Id: <20210427192135.17286-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfGTdjo5T48xJeOVTt/aK4+mcWMifwLzX2ZOzvKEUO/ITF/2zvhDuslxblLVbzIIPZU0a+fQJM0RGFMvLAq2Lv9XrMKF4+NG86T82GI4PXHp7Y58oMUvW Kj7eUfkxZXnsaMOlQm0G40Qs1bKb7EkQlX6eovu70xNEJLDyiqBeJ80P Subject: [FFmpeg-devel] [PATCH 1/4] avformat/rmdec: Check old_format len for overflow 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: cOz7bbYYit4y Maybe such large values could be disallowed earlier and closer to where they are set. Fixes: signed integer overflow: 538976288 * 8224 cannot be represented in type 'int' Fixes: 29102/clusterfuzz-testcase-minimized-ffmpeg_dem_RM_fuzzer-6704350354341888 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/rmdec.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index fc3bff4859..36765b4763 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -1012,8 +1012,8 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) { RMDemuxContext *rm = s->priv_data; AVStream *st = NULL; // init to silence compiler warning - int i, len, res, seq = 1; - int64_t timestamp, pos; + int i, res, seq = 1; + int64_t timestamp, pos, len; int flags; for (;;) { @@ -1032,7 +1032,9 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) ast = st->priv_data; timestamp = AV_NOPTS_VALUE; len = !ast->audio_framesize ? RAW_PACKET_SIZE : - ast->coded_framesize * ast->sub_packet_h / 2; + ast->coded_framesize * (int64_t)ast->sub_packet_h / 2; + if (len > INT_MAX) + return AVERROR_INVALIDDATA; flags = (seq++ == 1) ? 2 : 0; pos = avio_tell(s->pb); } else {