From patchwork Thu Feb 7 00:12:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chcunningham@chromium.org X-Patchwork-Id: 11982 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 738FA448FF5 for ; Thu, 7 Feb 2019 02:13:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 47F8168AA42; Thu, 7 Feb 2019 02:13:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D59168830A for ; Thu, 7 Feb 2019 02:13:18 +0200 (EET) Received: by mail-pl1-f182.google.com with SMTP id u18so3918760plq.7 for ; Wed, 06 Feb 2019 16:13:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=iTik0rSU9Ibn//H9qFPdhWIRP6t6xG3pfrkRgqziqj0=; b=mIpd1+m+RO/OjvjmzvTCKkYAIEbmiVKsYDr/F6o6NkMhr7EfUU36g/GuV+tluJqj8Q ck3A0NSButnNX2MgHOHLYP8Jos95Hvt/+fw62Lr8IITc+WYxRZ/nZRIlTJDdSKPCy7gy LxggNCz6e5G/2Z3Z/JliC8L3xnEygFGv4dRoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=iTik0rSU9Ibn//H9qFPdhWIRP6t6xG3pfrkRgqziqj0=; b=Gsjjsj4Ij536y8bA4Povo2V4Ebph7DfXtahXEbj4BC9+rTliy00Z3Uvh3x7wsRPW9n I7OzKLaY+hCCzkQ9ho1c3eS6dhDMtlkPz8Naver9V0LhDW4StspW9jLGJVfd7nGHqVyy IabBS1FBdxSszxQYWzmEqfDrFg9a10QLSZo0rdbYK6ceHpA5wyLonixLVOpby3IB63J3 y1Z4y93JDwSWGOGBi5Y0QFzhJsoUwZUilvFG3KFKSl/HYvV57JgsmOgmYNy1oOnYlut5 UWz2bqwwnn7bjv0ooVMAHhryY1fTOEtIKZbVK9EyndEKFYCwdfEKztjPFw1Kii3vno+X G2yA== X-Gm-Message-State: AHQUAubnlQAoMfOBR+tvc+14cjnUiyjF9y6saUCgUK++EEEKO6iUNg7e IjR/tSmgaBvSQParrtHM/ZbtzKtbm+U= X-Google-Smtp-Source: AHgI3IYIwxl+nTFZYsjrEb8wGpO8Fw1xRsGtxM3+jm5Ku3EOzifVSToaKQimbyywjM+u0SMhy5DXDA== X-Received: by 2002:a17:902:6b09:: with SMTP id o9mr13493606plk.208.1549498395866; Wed, 06 Feb 2019 16:13:15 -0800 (PST) Received: from chcunningham-linux.sea.corp.google.com ([2620:15c:38:200:74b:ad27:5acb:a21]) by smtp.gmail.com with ESMTPSA id x186sm9588305pfb.59.2019.02.06.16.13.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 16:13:15 -0800 (PST) From: chcunningham To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Feb 2019 16:12:51 -0800 Message-Id: <20190207001251.23599-1-chcunningham@chromium.org> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov.c: require tfhd to begin parsing trun 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Detecting missing tfhd avoids re-using tfhd track info from the previous moof. For files with multiple tracks, this may make a mess of the avindex and fragindex, which can later trigger av_assert0 in mov_read_trun(). --- libavformat/isom.h | 1 + libavformat/mov.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index e629663949..69452cae8e 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -87,6 +87,7 @@ typedef struct MOVAtom { struct MOVParseTableEntry; typedef struct MOVFragment { + int found_tfhd; unsigned track_id; uint64_t base_data_offset; uint64_t moof_offset; diff --git a/libavformat/mov.c b/libavformat/mov.c index 9b9739f788..6afb656dae 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1366,6 +1366,9 @@ static void fix_frag_index_entries(MOVFragmentIndex *frag_index, int index, static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + // Set by mov_read_tfhd(). mov_read_trun() will reject files missing tfhd. + c->fragment.found_tfhd = 0; + if (!c->has_looked_for_mfra && c->use_mfra_for > 0) { c->has_looked_for_mfra = 1; if (pb->seekable & AVIO_SEEKABLE_NORMAL) { @@ -4544,6 +4547,8 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVTrackExt *trex = NULL; int flags, track_id, i; + c->fragment.found_tfhd = 1; + avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4679,6 +4684,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVIndexEntry *new_entries; MOVFragmentStreamInfo * frag_stream_info; + if (!frag->found_tfhd) { + av_log(c->fc, AV_LOG_ERROR, "trun track id unknown, no tfhd was found\n"); + return AVERROR_INVALIDDATA; + } + for (i = 0; i < c->fc->nb_streams; i++) { if (c->fc->streams[i]->id == frag->track_id) { st = c->fc->streams[i];