From patchwork Thu May 16 22:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13178 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 0E0D0449B3C for ; Fri, 17 May 2019 01:51:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E355B68A6F3; Fri, 17 May 2019 01:51:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4D5F68A451 for ; Fri, 17 May 2019 01:51:16 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id r4so5045974wro.10 for ; Thu, 16 May 2019 15:51:16 -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=eI6soDEXLzgZCWwZQ56g1HNfz5xKebJNeh/lcJ+Dcb8=; b=Ufqn2mZ0G7izhNZir+e1XRqdV22bMMm2LnP1bwz2Y7yG5FsXTgsk2+AEjDD7Q6hg7A 93VN81V+qF3sSJz0J3u3FavYU2CP9nQ/TheZ0OvvafoZg9bM3PXbBxB3PXD66TlLIaQV d9OmPWXeDo+k1x9Hoz2rRgcX3/0bV1uwBCzCcveM/o9/4VewaLzNF0Cdm0LPZkZWFnob ZQXFa7IItqXBbWy4Qc5h4Mvv3t/nShDw2gnHWbrH7qKCOiozs0FQt6CcVEPEDhENyeMr 9RZOABHZM+aFhNN6/Xqz3KoUZCxhdRGK9gwD+OYNvDamulX+sa2R8brNP3nVdxks51Iw mGFQ== 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=eI6soDEXLzgZCWwZQ56g1HNfz5xKebJNeh/lcJ+Dcb8=; b=j19t+8q5bMG74KN0gbzXILFd8CmrDAHj/Jsc+opow/12gRRXF6hfXL6JqFjx723Vu+ 4dkyPDKAisq7x8dxu0TUyUd4YeH5RYr2oZL6S5Ov/WJzy+VepIx6FMeA2BzCvF9NqNLq xBRC7x7RfpAeZMBRLvStycyC1VnHKON3PomrEcTSdtccEPtxRh6x/5biaxi3Hqh+zcRF WGtH9R+G5LBDiZD6b4xxMx3h6Ai+t0hZqVVIeToXLzYfI/pnThKbbkycbZR1pzRirJC3 K8ySuEdgKJpHOHa7+GkBXv2MQ1gJ6a02Q04/61n1dTg65XEGEgm/zuxlyr1zDc1sEIBF xeOg== X-Gm-Message-State: APjAAAX5PIz7+f1A+ktTrkWdQSQMQaQGc+Rpzwx2hbghVqe6g9iVUP6p sSaZ6D1WDWB6ayu4C8bdmzsyfKHj X-Google-Smtp-Source: APXvYqySSPf+ley0OiVMgFp3ufCVe3i4Ydvw+cXx2zzESOl59sz1LwcFFFrvU9YD/AgoEPfs/wolpQ== X-Received: by 2002:adf:f9c3:: with SMTP id w3mr22787271wrr.271.1558046585605; Thu, 16 May 2019 15:43:05 -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.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 15:43:05 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2019 00:29:49 +0200 Message-Id: <20190516223018.30827-6-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 05/37] avformat/matroskadec: Get rid of cluster size field assumption 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" The earlier code relied on the length of clusters always being coded on eight bytes as was the behaviour of libavformat's Matroska muxer until recently. But given that our own Matroska muxer now (and mkvmerge from time immemorial) creates files that don't conform to this assumption, it is high time to get rid of this assumption. Signed-off-by: Andreas Rheinhardt --- I originally planed for this patch to get merged before my Matroska muxer patches. libavformat/matroskadec.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4dd933ef74..6fd5537f5a 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3711,15 +3711,17 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) cluster_pos = s->streams[0]->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { - int64_t cluster_id = 0, cluster_length = 0; + uint64_t cluster_id, cluster_length; + int read; AVPacket *pkt; avio_seek(s->pb, cluster_pos, SEEK_SET); // read cluster id and length - ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id); - ebml_read_length(matroska, matroska->ctx->pb, &cluster_length); - if (cluster_id != 0xF43B675) { // done with all clusters + read = ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id); + if (read < 0 || cluster_id != 0xF43B675) // done with all clusters + break; + read = ebml_read_length(matroska, matroska->ctx->pb, &cluster_length); + if (read < 0) break; - } avio_seek(s->pb, cluster_pos, SEEK_SET); matroska->current_id = 0; matroska_clear_queue(matroska); @@ -3728,7 +3730,8 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) break; } pkt = &matroska->queue->pkt; - cluster_pos += cluster_length + 12; // 12 is the offset of the cluster id and length. + // 4 + read is the length of the cluster id and the cluster length field. + cluster_pos += 4 + read + cluster_length; if (!(pkt->flags & AV_PKT_FLAG_KEY)) { rv = 0; break;