From patchwork Thu May 16 22:29:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13172 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 8A693449B3C for ; Fri, 17 May 2019 01:51:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7461268A755; Fri, 17 May 2019 01:51:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5FF368A6EE for ; Fri, 17 May 2019 01:51:26 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 7so4977116wmo.2 for ; Thu, 16 May 2019 15:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eTr2K/3b18dOk0xekofTw2WLjh1jtvR1nMr5Y1VWxSM=; b=ba1FhgJCtiktXdF0RmiMcA1R5sIHdngo4TvVWB1ykCuw9tYYlGNYx/JxhdP/U+tfwx MLRGfffIpvI2530yJMgB9kIa3JDsrloRbFo2un53kmKnCsy4bFR7W89ZVkO5aWlSkdOb aiBLOmYejo05xYbaS7Sk/Bf4z4N+BXOpoxSsMMalXhHsl/ciOGoWmaA3XAI1h7ANcOC4 pOXNPHKtHwV9INZ+MUsrloEq6RM0gTaFhpmBSRzhORtTsa8E/WIPoGHJJ+TRgXuJ/bKL itzS+g60LcQ85ON7IOgLOUjTKJUitTCvk/YJqmfK8ldGJcIMcdngnwWkUpcHjFlKSJw5 xBiw== 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=eTr2K/3b18dOk0xekofTw2WLjh1jtvR1nMr5Y1VWxSM=; b=qQW3k4kOucbEZpL2hlzurkWo1oe3ia9sS0ZCsMcybvP40sc28+z89dP42SKVCo7GqM CBQFSUX2iQAQ84X7RZ/jzio+4dQ6c22le9xQE665vTle1IHfvxD5yy40Ab32oIM6M9br 3O6S4weZjJKMmWR6UOL8/NE7JS34CxxIOdQSpLqX053dJWwEkx0v28HcsOraifccHxvW paNLdg18rt0QDe38qr4sK4RUjRmBBnNcYZ85tHqoe1hLrwI72z0T7geX5aR5gUyjHTr1 N/IXZOmCd+ORHEIqOdJM766f0W2VUdBaPMXKhyKbcbi8HfPny192jEq4t2bvZ1wYoD/y iEdQ== X-Gm-Message-State: APjAAAV1L9U4QHziW1ffImQ+FYUNrT3Hz58gXROi5S0QOezx49TYGCGe 8QDUKPVcnWHQVXVLvw6DAqUK69cZ X-Google-Smtp-Source: APXvYqy7EB6+jTmyq8xmBQVFA6cGwNTS02Z0er+Zk+13PhMKS9L8sYKLvmk7L0gIHrfGveRYmdQ8Wg== X-Received: by 2002:a1c:1941:: with SMTP id 62mr92756wmz.100.1558046587294; Thu, 16 May 2019 15:43:07 -0700 (PDT) Received: from localhost.localdomain (ipbcc18715.dynamic.kabel-deutschland.de. [188.193.135.21]) by smtp.gmail.com with ESMTPSA id i185sm11168725wmg.32.2019.05.16.15.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 15:43:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2019 00:29:51 +0200 Message-Id: <20190516223018.30827-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> References: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/37] 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: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt 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)) 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 927462d3ad..1cda5d5b76 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2669,6 +2669,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 == MATROSKA_ID_CLUSTER) + s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4; matroska_execute_seekhead(matroska); if (!matroska->time_scale)