From patchwork Sun Feb 10 04:44:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: no pls X-Patchwork-Id: 12017 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9482344768F for ; Sun, 10 Feb 2019 06:50:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7112068A7B9; Sun, 10 Feb 2019 06:50:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D86F468A768 for ; Sun, 10 Feb 2019 06:50:13 +0200 (EET) Received: by mail-yb1-f196.google.com with SMTP id v2so943165ybm.2 for ; Sat, 09 Feb 2019 20:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=b5I6bPlUE60HXLaQKe4FlRrX44jbzdRdkcn+Ro/H8Do=; b=iXatpwLU3wu7VsaktVGmqO0F13Gt5LMD1INPlIiUl5NWfqgm9mjKm4qmku1QODjByR zlhlhqTry0yMVRRELeXhH/RG/qCxUf/ozRlYxjKXlPk7h+gHt5P1BnULIAj9wKaOuUWf p8Mk8Fh9CKBOmoQIjMQA9zEGpsrK17XqgC8Cga4eOlyRkUaOSRlzqoNgLPpJLdlUGqev hoilHS3FyOFOv8Fv5W37hwfnjpXLVF265YN7dvwyELNIyAUFaTCZMPv/A8Oa19fFWrFn XOTxoD/0UrX/bjxYvanBY3LnS09YONpwJvHw3oK75gU1TKQ6kkspBsJJ1WQ3QQYStXzF YpZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=b5I6bPlUE60HXLaQKe4FlRrX44jbzdRdkcn+Ro/H8Do=; b=n2JUMicA0dWixC/6M7Psho5rFeLWRn/kaK3tux95JblZnYmmz5ozSkwTbaGlSalMDe xugi8yckT91vdhs8uJwnydZUHSs7cutRT+jN5eQD2jOJ6StTG5kamlqipuUusdTwL95P S+5kMcfTg2aHtQGp9HX8U4c4zlls5GlbDlTqDDcoVOBV10cZNC7TqgoDNpnh1BF3NgYd tTFBEpEnHmM/Fc/Rfa8KuAa/l8mR3e3k3Qxzl/7uzCAytm0+5Fvl5W1Tfa7BAxjjOVkK wj2A7HXQzMyVpm+Ys+p6b8TpSH3PA8cMzWfCoO4s1g9NnKIbGadMnGJpgzDZm3fi9owN f17g== X-Gm-Message-State: AHQUAubyndJmrkLMImCbhnZ0xw0/A4hCcPw3mnm68f6P2e+PjXPG5Sg6 G8+HxMC+yJXP0GHluhOok8FCLhAu X-Google-Smtp-Source: AHgI3IbVPTb7y+xmnPOnQRSRmCbHeQMV7ImAmJ3Z8LtSZZ8+P8dEdVoPtILoEMI5phrKMDUCrlQ6rw== X-Received: by 2002:a25:4047:: with SMTP id n68mr24576238yba.136.1549773902897; Sat, 09 Feb 2019 20:45:02 -0800 (PST) Received: from alterraid.attlocal.net ([2602:306:8385:d210:dc1a:7763:25f3:125b]) by smtp.gmail.com with ESMTPSA id 141sm2522251yws.47.2019.02.09.20.45.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Feb 2019 20:45:02 -0800 (PST) From: agrecascino123@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Feb 2019 23:44:52 -0500 Message-Id: <20190210044452.16820-1-agrecascino123@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: fix sidx loading issues in fragmented files. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: mptcultist Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: mptcultist fixed issue where if sidx was after another sidx and happened to point to the same media, it wouldn't be read. this is done by counting the sidx atoms before they're read. for #7572 --- libavformat/isom.h | 2 ++ libavformat/mov.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 69452cae8e..cc3067d2c0 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -288,6 +288,8 @@ typedef struct MOVContext { int decryption_key_len; int enable_drefs; int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd + int sidx_count; + int cur_sidx; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index cc91beb7f9..a59c893274 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4961,6 +4961,8 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc, *ref_sc = NULL; AVRational timescale; + c->cur_sidx++; + version = avio_r8(pb); if (version > 1) { avpriv_request_sample(c->fc, "sidx version %u", version); @@ -5027,7 +5029,8 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->has_sidx = 1; - if (offset == avio_size(pb)) { + if ((!(pb->seekable & AVIO_SEEKABLE_NORMAL) && (offset == avio_size(pb))) || + ((pb->seekable & AVIO_SEEKABLE_NORMAL) && (c->sidx_count == c->cur_sidx)) ) { // Find first entry in fragment index that came from an sidx. // This will pretty much always be the first entry. for (i = 0; i < c->frag_index.nb_items; i++) { @@ -6779,6 +6782,43 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { 0, NULL } }; +static int mov_count_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + int64_t total_size = 0; + MOVAtom a; + int si = 0; + + if (atom.size < 0) + atom.size = INT64_MAX; + while (total_size <= atom.size - 8 && !avio_feof(pb)) { + a.size = atom.size; + a.type=0; + if (atom.size >= 8) { + a.size = avio_rb32(pb); + a.type = avio_rl32(pb); + if (a.type == MKTAG('s','i','d','x')) { + si++; + } + total_size += 8; + if (a.size == 1 && total_size + 8 <= atom.size) { /* 64 bit extended size */ + a.size = avio_rb64(pb) - 8; + total_size += 8; + } + } + if (a.size == 0) { + a.size = atom.size - total_size + 8; + } + a.size -= 8; + if (a.size < 0) + break; + a.size = FFMIN(a.size, atom.size - total_size); + avio_skip(pb, a.size); + total_size += a.size; + } + avio_seek(pb, 0, SEEK_SET); + return si; +} + static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int64_t total_size = 0; @@ -7401,7 +7441,8 @@ static int mov_read_header(AVFormatContext *s) atom.size = avio_size(pb); else atom.size = INT64_MAX; - + if (pb->seekable & AVIO_SEEKABLE_NORMAL) + mov->sidx_count = mov_count_sidx(mov, pb, atom); /* check MOV header */ do { if (mov->moov_retry)