From patchwork Mon Sep 30 21:12:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51945 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a303:0:b0:48e:c0f8:d0de with SMTP id v3csp3201vqm; Mon, 30 Sep 2024 14:36:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUt7FZMIcEKJ8RO6u8NfsZYj4lY3mKMBbAX3h9wisOTUqA+MhOltl3lIX8boRPgtxQIivw4/wX3Vhxa6YBMvYLb@gmail.com X-Google-Smtp-Source: AGHT+IEGO5iqrtOl2Z6IhV9uJ8i3ikgimBp4hSpLCW9JhewAgEkjZaud0kkFGU8WmnhDTOEI7HBh X-Received: by 2002:a05:6000:184b:b0:374:d258:90d1 with SMTP id ffacd0b85a97d-37cde3b85f1mr3077093f8f.2.1727732172266; Mon, 30 Sep 2024 14:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727732172; cv=none; d=google.com; s=arc-20240605; b=V27NC5hZh5WpVBUDb89ZzWodpuGG0dzzBmBvRyqst5e5y1hcM/KGt4JEk4TqVXjK44 9ZAla5/TqoqHRY9xdcNtOBszT2yAquXnvSbZ3g/DdPyYNXpgW59A1IZXEjVFlvPrmHyB 9tODMBu2nP+shoQ81l9Mpi78kPJZJsHGHnd++vwVV5F60UEzILn4/DHcmIdhl0OfRajY bgw9AJG5Y2Wo4hduMjEx48TGsN3GPO4oFIhknhw+hOOV4Rl261ZDOtMp6XGhbYPsOfBN uVvQBMETowwF0o7uZVUgjlT6hX7YH+oh/Z1XHZOGMUPHBMkUdUlN+h/sgpymfhkyJ1Qw K9BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=LBPeZgcYuUiZbZEXmYmCuU52+AaFL0yOb54LJ/ALSkw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=ZOczjS7X11eVY9NQyy4o765rnKp+hAQLi5VSgnjDEZcwild3NOpL7y11QOHNAAMK2t bG6tG/2ujSkeL5LP5CKM2phlY5z+kaJZd84UEYD5rVpHdYd/RKj0HddPaTD1hgmHciu4 Nn4Pwm8SmDxxpXJSYPBUtj+DT6M7HrCnO4VlU8gVaqLVNFdKeppaf0loQty1REvAkEph oGgTqBB1Y6dyq5PUnIdMvo0zK3BAuu5LSoXlmK6zWXlLXkxMz9cRIDPeoj5xgkoigBcb cB9+69yCZvsJiRrBgKo+MzSukQCsPKdjBvMm1SjOYo3iZto3P1UAdZoI6bn0ZCiDHM1c T0tw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=YAnO8g0q; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a93c2a2eaf0si633163566b.835.2024.09.30.14.36.11; Mon, 30 Sep 2024 14:36:12 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=YAnO8g0q; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87F3D68DDB9; Tue, 1 Oct 2024 00:12:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 953A968CFBA for ; Tue, 1 Oct 2024 00:12:03 +0300 (EEST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7179069d029so3442030b3a.2 for ; Mon, 30 Sep 2024 14:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727730720; x=1728335520; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=m9/09dIroHbJjBDDRwzlh4kojd7LQmxlT8R6ul3Gdlc=; b=YAnO8g0qqduD/Y1GI3ZnSbgGA7Df6Yx06xzj31/RDG/uWKfUr0rFj1i3del39x7f95 C37Qss5+TYlUHuLjiBobRQ2G3NAfqrMgSTkThsNiMc/sG5YYVCupNEaucoV+MPlyXFbm AeyyVaD4QKFIug6M6NpmMHaRC+DNunP/VKG3dNxqGCHSKl/hTD0/pvQbFpFtjY0ZFeim l8dvgQjwnuMi18rTzAis/Jf3Fp46Rl20En5dhcIElBRuRydAT/3yNj4HQtpU2Yrz0XtU eJYPHhzqw6wA+VFZrxCJQmIC9HMYBquKTwbUp0xAT4VbZYNJLlQgdv4E6E0SZoj7D8CP 3mBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727730720; x=1728335520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m9/09dIroHbJjBDDRwzlh4kojd7LQmxlT8R6ul3Gdlc=; b=PYRZTwwYxtYtJnGcLvECquVv0BBuroAVbXFKbb5xkCLeG1Ha0Zo0roARqhj5wsAhpM v835zM5ZVnF4ZYBlRxeImj22sj2SLzCsPvv0lzZNUXSAaJ/Y9eVMJWCbZMKbcPMzcJM3 rL09bj2f/k4BewOtZEHjSSaIKn/5fZHkJSx+7bZ47nevxGlySG/Wsz5Gc54+o6O9i1cV nTL/IaTnrgmbBYqtscqKJtlPYXPn7bB5UD9fcvCPVN4TWORpKmvXQXSdI5jatlexEbVw 8tJrUavt1MnX3PDDo6BXD8Cwg02TLNVfakRTHHEODKbjgtPdW3wxgXMk681dX6W0gBnP bNHg== X-Gm-Message-State: AOJu0Yynj6R6T85bg5sQoVN48zKjF3/0cVieB3RpFTskIymWLt1vvH2O RXJj2WGho0SRXVGKe2JWiZB4dm2hd7OE3e4yqvlOXJAVjib3iU1dmIWSlg== X-Received: by 2002:a05:6a20:4db0:b0:1d3:5208:1ea6 with SMTP id adf61e73a8af0-1d4fa806ebbmr15692275637.45.1727730720381; Mon, 30 Sep 2024 14:12:00 -0700 (PDT) Received: from localhost.localdomain ([181.92.233.116]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2c8af2sm6993028a12.48.2024.09.30.14.11.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 14:11:59 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Sep 2024 18:12:37 -0300 Message-ID: <20240930211237.10761-1-jamrial@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930174119.6426-1-jamrial@gmail.com> References: <20240930174119.6426-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/mov: parse clap boxes that reference heif items 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: AQ8jRfa0TyZE Signed-off-by: James Almer --- libavformat/mov.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 33158ac4dd..fdf2238d47 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1234,14 +1234,26 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; + HEIFItem *item; AVPacketSideData *sd; + int width, height; AVRational aperture_width, aperture_height, horiz_off, vert_off; AVRational pc_x, pc_y; uint64_t top, bottom, left, right; - if (c->fc->nb_streams < 1) + item = heif_cur_item(c); + st = get_curr_st(c); + if (!st) return 0; - st = c->fc->streams[c->fc->nb_streams-1]; + + width = st->codecpar->width; + height = st->codecpar->height; + if ((!width || !height) && item) { + width = item->width; + height = item->height; + } + if (!width || !height) + return AVERROR_INVALIDDATA; aperture_width.num = avio_rb32(pb); aperture_width.den = avio_rb32(pb); @@ -1263,9 +1275,9 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den, horiz_off.num, horiz_off.den, vert_off.num, vert_off.den); - pc_x = av_mul_q((AVRational) { st->codecpar->width - 1, 1 }, (AVRational) { 1, 2 }); + pc_x = av_mul_q((AVRational) { width - 1, 1 }, (AVRational) { 1, 2 }); pc_x = av_add_q(pc_x, horiz_off); - pc_y = av_mul_q((AVRational) { st->codecpar->height - 1, 1 }, (AVRational) { 1, 2 }); + pc_y = av_mul_q((AVRational) { height - 1, 1 }, (AVRational) { 1, 2 }); pc_y = av_add_q(pc_y, vert_off); aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 }); @@ -1278,18 +1290,18 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) top = av_q2d(av_sub_q(pc_y, aperture_height)); bottom = av_q2d(av_add_q(pc_y, aperture_height)); - if (bottom > (st->codecpar->height - 1) || - right > (st->codecpar->width - 1)) + if (bottom > (height - 1) || + right > (width - 1)) return AVERROR_INVALIDDATA; - bottom = st->codecpar->height - 1 - bottom; - right = st->codecpar->width - 1 - right; + bottom = height - 1 - bottom; + right = width - 1 - right; if (!(left | right | top | bottom)) return 0; - if ((left + right) >= st->codecpar->width || - (top + bottom) >= st->codecpar->height) + if ((left + right) >= width || + (top + bottom) >= height) return AVERROR_INVALIDDATA; sd = av_packet_side_data_new(&st->codecpar->coded_side_data,