From patchwork Thu May 16 22:30:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13160 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 42C3144966A for ; Fri, 17 May 2019 01:45:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B1D4368A628; Fri, 17 May 2019 01:43:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22BFB68A4BD for ; Fri, 17 May 2019 01:43:31 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id j187so4962497wmj.1 for ; Thu, 16 May 2019 15:43:31 -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=cf+Lx3va+xGeLJDIxVAzfrW/RfprCpAs7Rxia72HfBs=; b=uGgVxD6OZ3Tg4SbcUVlvmG78bPVMAnNf4ANdkyY+Q9EbSdheDEOCkI692zq9axcPpn it6I6285d49K6xGcK3UkWulmVhHWu5KgEX4pjR89eOgAcwxVGqPQK+LEKhzzU1ZAK6jY QVmv6Uw0lCSjbt2LsI9AAl0J3+W7yImcxqBQXW5nRpQWRDTBJaskxxxfVEruZzZ9MUBE 3Cquq6R1Bvdv7lM7UTTFcC4dgKdJE4cIiaim9Hxhot4kYRFOrjadIzvFh4xuM6d+SEj6 53My9mwe7oMrj08Pcn0V/LBw0Ivl04ChglDWX5kjbHnasjlRnBjQd8rg6zXq4IGahaEL 4ruw== 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=cf+Lx3va+xGeLJDIxVAzfrW/RfprCpAs7Rxia72HfBs=; b=Z0YiCTgTkaIPB2zsIIQOazZf9ZXuM9qsTyf9Nio7sZgXZHDXK8uG1we4u2IsMTrZYk 3HMHrr9ulvgJ0vUEjCo9zjThCgILdi8x1Mjy3HGDxVN6ks+uBSlN3Np8XArlpu5OuIDH TgZX17AYIazuNEehnptNm1Klz/wdr0RrLnFdRA8n5sJzSI0lexWsoc1ZbKGDAoYy2JH7 vPmVOvteY9yd8Fa+yNRzgzCcQii/GeecIHcUcxQx71LiqS4RjEV0NIMOMfw38BGoBSi7 98O9/h4qNOZmZ+TyP5KSRLTVoB+0LTqC0ULX24HcpvHn3JfTzQs+wYHGiqQ9Oji+wmZf 3LFQ== X-Gm-Message-State: APjAAAXtnP/kcVd2W2X50s+8V0UbLX0b/Hegqwxfatbi1HZAvuPWtt20 rn50rITkytTGAHrihRLIT5tSpE5W X-Google-Smtp-Source: APXvYqxmlWZ0hQwbKOT60InR8CGrvrCRTdXthYzDavsiASEGhum2sNXAwpZZvSW7iOiQdUl+IwvoEA== X-Received: by 2002:a1c:e90f:: with SMTP id q15mr81912wmc.1.1558046610373; Thu, 16 May 2019 15:43:30 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 15:43:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2019 00:30:18 +0200 Message-Id: <20190516223018.30827-35-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 34/37] avformat/matroskadec: Accept more unknown-length elements II 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" Up until now, one last kind of unknown-length element hasn't been properly handled: Unknown-length elements that are supposed to be skipped, i.e. the level 1 elements that might reside after the clusters. This commit changes this. To do this, ebml_parse got a mode that essentially tries to skip everything except when parsing is needed (namely for unknown-length elements for which parsing is necessary as they can't be skipped). This mode is selected by using a NULL as destination where the parsed data should be written to. It is used to parse the level 1 elements in matroska_parse_cluster. The syntax list used for parsing must of course include links to the syntax of all the master elements that might need to be parsed. In other words: Instead of matroska_clusters (which contained every level 1 element except clusters as EBML_NONE elements designated to be skipped) matroska_segment is needed and used; matroska_clusters has been removed. Furthermore, matroska_segment has been reordered so that clusters are at the front as this is now the most common case for this list. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index edf21e5fe2..dfd5691b5a 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -685,6 +685,7 @@ static const EbmlSyntax matroska_seekhead[] = { }; static const EbmlSyntax matroska_segment[] = { + { MATROSKA_ID_CLUSTER, EBML_STOP }, { MATROSKA_ID_INFO, EBML_LEVEL1, 0, 0, { .n = matroska_info } }, { MATROSKA_ID_TRACKS, EBML_LEVEL1, 0, 0, { .n = matroska_tracks } }, { MATROSKA_ID_ATTACHMENTS, EBML_LEVEL1, 0, 0, { .n = matroska_attachments } }, @@ -692,7 +693,6 @@ static const EbmlSyntax matroska_segment[] = { { MATROSKA_ID_CUES, EBML_LEVEL1, 0, 0, { .n = matroska_index } }, { MATROSKA_ID_TAGS, EBML_LEVEL1, 0, 0, { .n = matroska_tags } }, { MATROSKA_ID_SEEKHEAD, EBML_LEVEL1, 0, 0, { .n = matroska_seekhead } }, - { MATROSKA_ID_CLUSTER, EBML_STOP }, { 0 } /* We don't want to go back to level 0, so don't add the parent. */ }; @@ -740,18 +740,6 @@ static const EbmlSyntax matroska_cluster_enter[] = { { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = &matroska_cluster_parsing[2] } }, { 0 } }; - -static const EbmlSyntax matroska_clusters[] = { - { MATROSKA_ID_CLUSTER, EBML_STOP }, - { MATROSKA_ID_CUES, EBML_NONE }, - { MATROSKA_ID_TAGS, EBML_NONE }, - { MATROSKA_ID_INFO, EBML_NONE }, - { MATROSKA_ID_TRACKS, EBML_NONE }, - { MATROSKA_ID_ATTACHMENTS, EBML_NONE }, - { MATROSKA_ID_CHAPTERS, EBML_NONE }, - { MATROSKA_ID_SEEKHEAD, EBML_NONE }, - { 0 } /* We don't want to go back to level 0, so don't add the parent. */ -}; #undef CHILD_OF static const char *const matroska_doctypes[] = { "matroska", "webm" }; @@ -1078,6 +1066,7 @@ static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, { int i, res; + if (data) { for (i = 0; syntax[i].id; i++) switch (syntax[i].type) { case EBML_UINT: @@ -1105,6 +1094,7 @@ static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, matroska->num_levels--; return 0; } + } do { res = ebml_parse(matroska, syntax, data); @@ -1234,6 +1224,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, update_pos = 0; /* Don't update resync_pos as an error might have happened. */ } + if (data) { data = (char *) data + syntax->data_offset; if (syntax->list_elem_size) { EbmlList *list = data; @@ -1246,6 +1237,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, memset(data, 0, syntax->list_elem_size); list->nb_elem++; } + } if (syntax->type != EBML_STOP) { matroska->current_id = 0; @@ -1362,6 +1354,9 @@ static int ebml_parse(MatroskaDemuxContext *matroska, // of the element as the "last known good" position. matroska->resync_pos = pos; } + + if (!data && length != EBML_UNKNOWN_LENGTH) + goto skip; } switch (syntax->type) { @@ -1400,6 +1395,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, break; case EBML_STOP: return 1; + skip: default: if (length) { if (ffio_limit(pb, length) != length) { @@ -3663,7 +3659,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) av_assert0(matroska->num_levels <= 2); if (matroska->num_levels == 1) { - res = ebml_parse(matroska, matroska_clusters, NULL); + res = ebml_parse(matroska, matroska_segment, NULL); if (res == 1) { /* Found a cluster: subtract the size of the ID already read. */