From patchwork Wed Mar 27 11:18:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Felix de Souza via ffmpeg-devel X-Patchwork-Id: 12475 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 8B4DA448C86 for ; Wed, 27 Mar 2019 13:20:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 781C668A93A; Wed, 27 Mar 2019 13:20:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9700068A92E for ; Wed, 27 Mar 2019 13:20:40 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id z11so15871334wmi.0 for ; Wed, 27 Mar 2019 04:20:40 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HPq5iIoqfzHAtzqeldCUhcLUrxF46BMErsAeFg4ctHI=; b=aeeZ7QZw0iWoz3+Pn1RfZHvbmJGaxUp+qTZjHIfR4RwStVuER5KnZtkuhGNNuzWJgS syCXRrU5jA4jenBFliihEvtSpnneIDoYBAY1wfX4xUWM8gEjJVhrDQRCq3x5owFIQnaL 5DEBQM1zhddEgSstf7L7xHUYc1BL/DM0oNH3C7AHWlJp2LxCbMQrNAhNcaZCmU3vXuEa +LjtbCrfMdwBZ1B26+gP8bHHF4HihrYYlUCE+cZ+wM4GC1YQd6e6gic+r+gNKewkwdRV 7K4/SHk2WtpbcZN4Xs8lEA+60UVJpQFA3cPhnc0gdFw60ny5cqFA3cB/PXVIG1feCaUd TNeg== X-Gm-Message-State: APjAAAVx3pEszjw06UpwdcOZEPGr6JK0F/LtCeOsKDJa9OLjqj4Qo6Js 1t1YkWO9yvXy7KJTYVA8oRfL/OmnMFY= X-Google-Smtp-Source: APXvYqydvsUr1fWKUqTeiPDU0ZX8ivsGb31zUVckdhPG/nkdPFA3hGh6ZO0hqPfV6KIqbecx3h+tew== X-Received: by 2002:a1c:3d6:: with SMTP id 205mr11818913wmd.66.1553685639931; Wed, 27 Mar 2019 04:20:39 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id h10sm31745448wrs.27.2019.03.27.04.20.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 04:20:39 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Mar 2019 12:18:36 +0100 Message-Id: <20190327111852.3784-6-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190327111852.3784-1-andreas.rheinhardt@googlemail.com> References: <20190308092604.3752-1-andreas.rheinhardt@googlemail.com> <20190327111852.3784-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/21] avformat/matroskadec: Set offset of first cluster 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: , X-Patchwork-Original-From: Andreas Rheinhardt via ffmpeg-devel From: Diego Felix de Souza via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" By default, the data_offset member of the AVFormatInternal of the AVFormatContext associated with the MatroskaDemuxContext has not been initialized explicitly by any Matroska-specific function, so that it was initialized by default to the offset at the end of matroska_read_header, i.e. usually to the offset of the length field of the first encountered cluster. This meant that in case that the Matroska-specific seek-code fails because there are no index entries for the target track a seek to data_offset would be performed and ordinary parsing would start from there which is nonsense: The length field would be treated as EBML ID and (if the length field is not longer than four bytes (EBML numbers that long are rejected as invalid EBML IDs)) and whatever comes next would be treated as its EBML size although it simply isn't. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 49f8ff4082..f9811b54a1 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2651,6 +2651,9 @@ static int matroska_read_header(AVFormatContext *s) pos = avio_tell(matroska->ctx->pb); res = ebml_parse(matroska, matroska_segment, matroska); } + /* Set data_offset as it might be needed later by seek_frame_generic. */ + if (matroska->current_id) + s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4; matroska_execute_seekhead(matroska); if (!matroska->time_scale)