From patchwork Wed Dec 22 11:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 32833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6291608iog; Wed, 22 Dec 2021 03:31:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJygrKZM1op3rpwu1EKfRBMHMhKWaRsYE4lotNJEVQYHAMCTBlVSdPS+pAYWtnZKWMiFjqGv X-Received: by 2002:a05:6402:51d3:: with SMTP id r19mr2473932edd.271.1640172673580; Wed, 22 Dec 2021 03:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640172673; cv=none; d=google.com; s=arc-20160816; b=vEqcAl6hoJ3AKUGpCEcWEdiaanc8st7lhRyGZ97JxVmtoG/pZe1/rhQfX4zLx0ya0Y agJO6ee41Um/U6giny2hAXZYR17zdDAVsoF5PbQY5JpXWUycrFGA1QASOYs3gCi2gzAg oYfGRYUCp8rrPCvERU5cy/F6POzv3J1zSaeQtQjY2KdfQi4/Unv1T6VkJ0iq770MZBNi RvqHuGJrzjaEYjoKzORiHli4GdeNfsv7OPSfL8CQuXKYSuTIT1TvC5X9t9FAlWSHNCAW urAGw/Zl9EvFYTZeRsdxIWK+Ag+yCdltthJx6xKFkf5+f3nFxDPq8VywtbkHIh9nzRT8 Sz6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=txNtK72bfjazAEzj5/wfQzbTa0nzRJ2OIdqLxTyZSSw=; b=HnMDM34nmfAkUwfnqy097AGyyXYPjBRAaBrZgvhZrSSbnsrKl/+dDHm8lo5zuUiJgt NXXfVbBKjbGxElnDatn9y6/TgF4wpcoJckteO06GS3DWWoS2QSgcSnJWsX8f6Hhtvamp EYsVv+7FAGGGKNcftFyaa3VO0V4N95JKG0VJxgzFC1O34HHpEab+JcDD7jicGkAPztNK LH6T/IR0tf2eIK0lhCZnhZjwW4qjOFbi4EBYiPIzGpSrjPmhWcUdkrL+sVZFsrM6Fmmh 30I0APBNZf6xSefZixnwLzk/K4TlvUYfxAQaBuZQwiLq8SlEx6BgU55viq0GysxtKw+y 2yJg== 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 do16si1005547ejc.671.2021.12.22.03.31.13; Wed, 22 Dec 2021 03:31:13 -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 B267B68AD39; Wed, 22 Dec 2021 13:31:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6575D68AFAA for ; Wed, 22 Dec 2021 13:31:04 +0200 (EET) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4JJrjz4JngzQk3h for ; Wed, 22 Dec 2021 12:31:03 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Dec 2021 17:00:32 +0530 Message-Id: <20211222113033.7132-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: add validate_box_size 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SkfBhpETCTPN Helper function to check if stored box size is correct and looks to be fully available. --- libavformat/mov.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 2aed6e80ef..2cc9e699de 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -80,6 +80,38 @@ static int mov_read_mfra(MOVContext *c, AVIOContext *f); static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, int count, int duration); +/** Check if the box size meets the requirements passed in limit and constraint_type. + * If input avio_size is valid, it checks if box size appears to be available. + * + * constraint_type may be + * 0 if the box size has to be exactly equal to limit + * -1 if the box size has to be at most limit + * 1 if the box size has to be at least limit + * + * Returns 0 if size meets requirements. + */ +static int validate_box_size(MOVContext *c, MOVAtom atom, AVIOContext *pb, + int64_t pos, int64_t limit, int constraint_type) +{ + int size_fit; + int64_t input_size = avio_size(pb); + + if (input_size > 0 && + input_size - pos < atom.size) { + av_log(c->fc, AV_LOG_ERROR, "Box %s is truncated\n", av_fourcc2str(atom.type)); + return AVERROR_INVALIDDATA; + } + + switch(constraint_type) { + case 0: size_fit = atom.size == limit; break; + case -1: size_fit = atom.size <= limit; break; + case 1: size_fit = atom.size >= limit; break; + default: return AVERROR_INVALIDDATA; + } + + return !size_fit; +} + static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb, unsigned len, const char *key) {