From patchwork Thu Mar 26 00:41:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18402 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 09B324482A4 for ; Thu, 26 Mar 2020 02:42:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E1E3268B547; Thu, 26 Mar 2020 02:42:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74DDB68B128 for ; Thu, 26 Mar 2020 02:42:10 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id d5so5831767wrn.2 for ; Wed, 25 Mar 2020 17:42:10 -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=jDB4FCairLONYmTT7t/DKhE1fynWdlHjrJlLpsT0G1w=; b=Qz322Y6+2Co0q4W2FU2NPOLOdAYo/ef5jWXCdgnl7rxj1GIR59CDrvv672tElvpkmW lNn9dM+A/hoVCJlwuiFBasi+i2Qem5B2Yk7o1BF1n57d9RA3xBxePbyM1TUTQbOgffHt 81q/z/CtElE7VNUlpndg0cMxGpMh/wFb42YCAV3C/0Lm5jRCp1aGrDV5m4XOkFbNKugj /69Ex/yYCk8QMp0xn6LPsy9w50+aPMRYuh1qWtTNM0hoSbgHra3kusnLy9dbkhgn1k68 yebagzi6XhAM4JDCJKniwheMJNlVI0WSALy+G6xCqHPUJv3gKK9Y5FiFmJKFKHJRkiWK vbbA== 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=jDB4FCairLONYmTT7t/DKhE1fynWdlHjrJlLpsT0G1w=; b=rl4GnCY/LRckdhiOegRZmqxKjOxFpz6oB7bH1eDGXvNNDeMrLS2eO7km7lXD3lDVti WMJg7Qk3saCAGV/AnWyV8OwF3ubxtRcydrIjdx4HCSjKR9lsYmKlKB1AeQp8zAEotpKK LFxTaX5NNOR7zo5hjNoKq9DyY38YEmp/T+jjMQR1duArpbDlUQsmLohReJUbZy+qE831 dksFnb1udSbRYGy4mtmS7QQkCSPI6xyJ056mpz/zdVP2bnUW+9SULH+mIICqXWVrfGjp 0skLKyBmP3TPzerlejgH+PZGTXszK78+0KMQ7av5ix1f87HO+NdlLIIAJUaSiFCYRpFS FIOg== X-Gm-Message-State: ANhLgQ0+mxnmB/DpEP3hIY8WQ/G/YU7QJP2LxdLq8yFqaxtuKvd8EGvR uzRfv38KuQsYXFIBpi49CY3/ODEl X-Google-Smtp-Source: ADFU+vsef0gRg34IiFfFmX1/S8mMfb1cwsBHFPbATEzi6KomOZ5ccTzR55S/QMUwzpvt7QCKvr2F7Q== X-Received: by 2002:adf:a18b:: with SMTP id u11mr6588998wru.390.1585183329545; Wed, 25 Mar 2020 17:42:09 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id q72sm1142723wme.31.2020.03.25.17.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 17:42:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Mar 2020 01:41:44 +0100 Message-Id: <20200326004144.26758-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200326004144.26758-1-andreas.rheinhardt@gmail.com> References: <20200326004144.26758-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/matroskadec: Improve forward compability 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" Matroska is built around the principle that a reader does not need to understand everything in a file in order to be able to make use of it; it just needs to ignore the data it doesn't know about. Our demuxer typically follows this principle, but there is one important instance where it does not: A Block belonging to a TrackEntry with no associated stream is treated as invalid data (i.e. the demuxer will try to resync to the next level 1 element because it takes this as a sign that it has lost sync). Given that we do not create streams if we don't know or don't support the type of the TrackEntry, this impairs this demuxer's forward compability. Furthermore, ignoring Blocks belonging to a TrackEntry without corresponding stream can (in future commits) also be used to ignore TrackEntries with obviously bogus entries without affecting the other TrackEntries (by not creating a stream for said TrackEntry). Finally, given that matroska_find_track_by_num() already emits its own error message in case there is no TrackEntry with a given TrackNumber, the error message (with level AV_LOG_INFO) for this can be removed. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7aea13dda0..cd85d3e281 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3522,13 +3522,16 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf size -= n; track = matroska_find_track_by_num(matroska, num); - if (!track || !track->stream) { - av_log(matroska->ctx, AV_LOG_INFO, - "Invalid stream %"PRIu64"\n", num); + if (!track || size < 3) return AVERROR_INVALIDDATA; - } else if (size < 3) - return AVERROR_INVALIDDATA; - st = track->stream; + + if (!(st = track->stream)) { + av_log(matroska->ctx, AV_LOG_VERBOSE, + "No stream associated to TrackNumber %"PRIu64". " + "Ignoring Block with this TrackNumber.\n", num); + return 0; + } + if (st->discard >= AVDISCARD_ALL) return res; av_assert1(block_duration != AV_NOPTS_VALUE);