From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 62BFA44B52 for ; Fri, 18 Jul 2025 00:55:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id C09C368F2CA; Fri, 18 Jul 2025 03:55:35 +0300 (EEST) Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 9184C68F298 for ; Fri, 18 Jul 2025 03:55:29 +0300 (EEST) Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-41b7d12401bso873766b6e.1 for ; Thu, 17 Jul 2025 17:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752800127; x=1753404927; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=WnCxX6NraqOGjflgg7iosGbXZLuZ2AiOwJkawPUDhNk=; b=j6Ab/XD4Zladk5mP/y3az/0i16cdcrMdjRro3QTviZC4H3tH2pmfex4hav6CJRNqmI yBgDaTuscGO3TqnQufdu0yUME/NX9mSj1KkU6JUztrnGl96St+E1xiNlgENyOzNYVLdz 170tpF1emcyqM4UosjoucuF7lLneoRPZ1pfWoyFI50yawdOxQiz92TX2j7tJhKcXmShF HPzK1gsBvwLacX0Rog6mSSsrzyCjjj1f3BNR3J8cw99BHSQ8KK08MhEEwA0As/IHdLXP AgFcFHvtFVQGzy7A5RvHPNI583sTupAUYwYhCFPW94AFFEojokKmrcSO8/j5FCD8Gyiz sBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752800127; x=1753404927; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WnCxX6NraqOGjflgg7iosGbXZLuZ2AiOwJkawPUDhNk=; b=qeja+iTK78IAg9fzAQjJz8sgb78+cCd58YJlEIf5UIkMViVnir2Qr4uKa8i+RoAWRj duLFgs9Fpwsv20yfV1rvFtbT41kW8RBgFDEMnENc7daRDKfmCyMPtV2HF+cuIdanAGQg laeapvoAxwyK7zz8IivJx3tVOUABpXWQLykWx6a52rb5kANrx4dN7vyXtBqNVXPrfOcy Dd6hqyDT1ONbs5GSGB0S598MtZKafowYVgkldBJPZ7QdBx9Etw5MFTeI/u6RVSymxbg6 EAjcaRIbH3zVFC1gvwhXuhb5ZXoz/xfIz7qdeF+zxIPx2dpRkl2uZxt8QPbsOSKXPz3+ gHFg== X-Gm-Message-State: AOJu0Yw6vlo3GH3KpPbTMHjmxkbrtVpJ9myX6EglKQaX8cLrcdm1MPm0 u8EajMickl2CXj3IOHjoLDu+0jniBukoF1cZjS1cQv6jjaOfiDmK5PI7rGwAEw== X-Gm-Gg: ASbGnctH2ix57YVE14BfKmUfp4UsMW/0WJYQmErCekz3NI12nTkN8r0tw7+gNUAGfvf eMTNHmMUBqAi5gteO0SzWmayvE/LjIfYY2F5awiItGQmZl7d/tIDS7Ld0pnuEKSwAj4f1d1gQA8 BRF0Hadcgol5TwZpFjioJR5WwtpbBGRB6jGwVxLGRtB3hZq2zSahSemQ+HnghdGFhm60SCdjfQC m66w0KT0jNNp6YP5ueSBAnxtNkOWTFa66wR6LAf9yVA1MV4S9jjczPiLl9ReNkCSaviD/wksMUl vvSY9tfGWomRMqHM0NzZPIQBWxcWJyyCX0O47+6q3K60x+gqZb8HD4BEfRNvlnmtTWyJyaWMmir fRjMyfbmk3sBU1op6bJU= X-Google-Smtp-Source: AGHT+IH69DGiyOmp9jYNUA8SzQPy5N9/TzYnA1EtWY1ImP5pLNqMBgxiLHMTfMJ0HaMqXaL9Uu114g== X-Received: by 2002:a05:6808:4f54:b0:41b:51c4:3db0 with SMTP id 5614622812f47-41cee274b50mr7325499b6e.1.1752800127206; Thu, 17 Jul 2025 17:55:27 -0700 (PDT) Received: from Gryph ([2800:2121:b000:82e:187:ed8b:1b58:c460]) by smtp.gmail.com with ESMTPSA id 5614622812f47-41fd5951f20sm68970b6e.44.2025.07.17.17.55.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 17:55:26 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Jul 2025 21:55:18 -0300 Message-ID: <20250718005518.1462-1-jamrial@gmail.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: don't assume iloc and iinf entries for each item_id will be in the same order 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Nothing forbids them to be in any order the muxer desires. Fixes demuxing heif samples generated by S1II. Signed-off-by: James Almer --- libavformat/mov.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 836bdfb4e1..ccaa988e4b 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8739,7 +8739,7 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "iloc: item_count %d\n", item_count); for (int i = 0; i < item_count; i++) { - HEIFItem *item = c->heif_item[i]; + HEIFItem *item = NULL; int item_id = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); int offset_type = (version > 0) ? avio_rb16(pb) & 0xf : 0; @@ -8765,8 +8765,14 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) base_offset > INT64_MAX - extent_offset) return AVERROR_INVALIDDATA; - if (!item) - item = c->heif_item[i] = av_mallocz(sizeof(*item)); + for (int j = 0; j < c->nb_heif_item; j++) { + item = c->heif_item[j]; + if (!item) + item = c->heif_item[j] = av_mallocz(sizeof(*item)); + else if (item->item_id != item_id) + continue; + break; + } if (!item) return AVERROR(ENOMEM); @@ -8776,18 +8782,18 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) item->is_idat_relative = 1; item->extent_length = extent_length; item->extent_offset = base_offset + extent_offset; - av_log(c->fc, AV_LOG_TRACE, "iloc: item_idx %d, offset_type %d, " + av_log(c->fc, AV_LOG_TRACE, "iloc: item_idx %d, item->item_id %d, offset_type %d, " "extent_offset %"PRId64", extent_length %"PRId64"\n", - i, offset_type, item->extent_offset, item->extent_length); + i, item->item_id, offset_type, item->extent_offset, item->extent_length); } c->found_iloc = 1; return atom.size; } -static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom, int idx) +static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom) { - HEIFItem *item; + HEIFItem *item = NULL; AVBPrint item_name; int64_t size = atom.size; uint32_t item_type; @@ -8827,22 +8833,27 @@ static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom, int idx) if (size > 0) avio_skip(pb, size); - item = c->heif_item[idx]; - if (!item) - item = c->heif_item[idx] = av_mallocz(sizeof(*item)); + for (int i = 0; i < c->nb_heif_item; i++) { + item = c->heif_item[i]; + if (!item) + item = c->heif_item[i] = av_mallocz(sizeof(*item)); + else if (item->item_id != item_id) + continue; + break; + } if (!item) return AVERROR(ENOMEM); if (ret) - av_bprint_finalize(&item_name, &c->heif_item[idx]->name); - c->heif_item[idx]->item_id = item_id; - c->heif_item[idx]->type = item_type; + av_bprint_finalize(&item_name, &item->name); + item->item_id = item_id; + item->type = item_type; switch (item_type) { case MKTAG('a','v','0','1'): case MKTAG('j','p','e','g'): case MKTAG('h','v','c','1'): - ret = heif_add_stream(c, c->heif_item[idx]); + ret = heif_add_stream(c, item); if (ret < 0) return ret; break; @@ -8884,7 +8895,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) ret = AVERROR_INVALIDDATA; goto fail; } - ret = mov_read_infe(c, pb, infe, i); + ret = mov_read_infe(c, pb, infe); if (ret < 0) goto fail; if (!ret) -- 2.50.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".