From patchwork Sat Jul 2 12:22:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 36593 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1624169pzh; Sat, 2 Jul 2022 05:23:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uewH7GWlxGkGAQqtFQB9TRa0/Rsfnp1B2vh0yvcCn98USmu89XoHRv740y27vwXO1x0Zda X-Received: by 2002:a05:6402:43c5:b0:435:89ee:578f with SMTP id p5-20020a05640243c500b0043589ee578fmr25826302edc.225.1656764639486; Sat, 02 Jul 2022 05:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656764639; cv=none; d=google.com; s=arc-20160816; b=pLmA94Z7urzbt/REkVnoLCpBPOFKebROci+P9QRqhR2pOYYGK/PwuW3ef7TylDFzsG ks9haQQyvQ7Qwuu5KXfw1EPiEVQbiz+j+lDHHAVo5Opc5dA/llFtn8fHc7YS6n2EBp4L NVUIFFLWV0SeH5uiWFw3/inJESvWKYThw5/efJxdSCYOxBUdo0U0zMJSAtfCshMdDkTw oa1rikVistkjV8IlzmKihqh5oH9vJn6ftyp9KK2Pxq26uwfZH+sQ0a1V6uq5O8Sj/+wC hNjlXD5eBBGu0xIrIgdjz3nnEcB+e8Pk8TMTYYAZA4Dbf6pZZKxJrdXoBcMPqKAKi+IC YzEA== 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=aE/fcKEkvj0Z8e2HRTnImDzy8x2vKaJyz8Oow7kW1Zw=; b=FZX72hUfLue4xl1HLxR1MxeCdGzkXjEae/JSVgIUPEvKsZpmogJaMYzoyR1srUWzg7 36quSnqBrafiSiik62H2rWezij75EWr2zUcIZG6mHgmI802DGQBtoKgCMYJF7U9e+tW7 3kAbnDvgBTV14AFLnAy/Jr6uH1iS6wW5e82KqxCptnBrLWlK63rYl6lKZ+BJhpUH6nyj u0V6TaPPj9oYf/5I/0ADma57qCMy23ir3uzptbKaVu+CC94O7wrFeaM1ZL+w/wvV9uVd SjyxA6U/fJbgQ6j1kEGCJh5CMWULtmXsAs3yMOt/NownhtMmSmYxmwYDKOG6LAf9JrbV jXTA== 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 cq2-20020a056402220200b004315dd76796si291280edb.482.2022.07.02.05.23.59; Sat, 02 Jul 2022 05:23:59 -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 444F868B8DD; Sat, 2 Jul 2022 15:23:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at01-1.mx.upcmail.net (vie01a-dmta-at01-1.mx.upcmail.net [62.179.121.145]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 88D7B68B818 for ; Sat, 2 Jul 2022 15:23:51 +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 1o7cAB-0018eA-1U for ffmpeg-devel@ffmpeg.org; Sat, 02 Jul 2022 14:23:51 +0200 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 7c3foncuz8s8U7cABob2rn; Sat, 02 Jul 2022 14:23:51 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id 7c9DonlS38eSW7c9DonhTn; Sat, 02 Jul 2022 14:22:51 +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=KKE5sHJo c=1 sm=1 tr=0 ts=62c0389b a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=MazWSALGJ61ztWUSj04A:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 2 Jul 2022 14:22:49 +0200 Message-Id: <20220702122250.23065-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220702122250.23065-1-michael@niedermayer.cc> References: <20220702122250.23065-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBzP7iL67873L8xHmNFn7xFpRs0aK/gbfurG+wwtQ6vw1z/e8I03KX9KJ1yuwJgmWcIebLNm+Ox9UXuTadP3d3ZPbvrpL8hKDMEGMqOFkTqRdtGGcFI0 kubwD2A7FSReIEDT4FzOXk4HYDwRePQuF3vHK4RlVDPV3CY6qCpd52BFkDiJGkU91Dgeqfcpv5k9CQ== Subject: [FFmpeg-devel] [PATCH 2/3] avformat/cinedec: Check size and pos more 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: 27o8rcw+7nxW Fixes: signed integer overflow: 9223372036848019263 + 134232320 cannot be represented in type 'long' Fixes: 48155/clusterfuzz-testcase-minimized-ffmpeg_dem_CINE_fuzzer-5751429207293952 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/cinedec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c index f4779b2676..e8d9657ee1 100644 --- a/libavformat/cinedec.c +++ b/libavformat/cinedec.c @@ -273,10 +273,11 @@ static int cine_read_header(AVFormatContext *avctx) /* parse image offsets */ avio_seek(pb, offImageOffsets, SEEK_SET); for (i = 0; i < st->duration; i++) { - if (avio_feof(pb)) + int64_t pos = avio_rl64(pb); + if (avio_feof(pb) || pos < 0) return AVERROR_INVALIDDATA; - av_add_index_entry(st, avio_rl64(pb), i, 0, 0, AVINDEX_KEYFRAME); + av_add_index_entry(st, pos, i, 0, 0, AVINDEX_KEYFRAME); } return 0; @@ -302,10 +303,10 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR_INVALIDDATA; avio_skip(pb, n - 8); size = avio_rl32(pb); - if (avio_feof(pb)) + if (avio_feof(pb) || size < 0) return AVERROR_INVALIDDATA; - if (cine->maxsize && sti->index_entries[cine->pts].pos + size + n > cine->maxsize) + if (cine->maxsize && (uint64_t)sti->index_entries[cine->pts].pos + size + n > cine->maxsize) size = cine->maxsize - sti->index_entries[cine->pts].pos - n; ret = av_get_packet(pb, pkt, size); @@ -313,7 +314,7 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) return ret; if (ret != size) - cine->maxsize = sti->index_entries[cine->pts].pos + n + ret; + cine->maxsize = (uint64_t)sti->index_entries[cine->pts].pos + n + ret; pkt->pts = cine->pts++; pkt->stream_index = 0;