From patchwork Thu Apr 23 03:07:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19190 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 B352444BA43 for ; Thu, 23 Apr 2020 06:08:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9860568BE38; Thu, 23 Apr 2020 06:08:27 +0300 (EEST) 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 75AB568BE05 for ; Thu, 23 Apr 2020 06:08:15 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id x17so4291698wrt.5 for ; Wed, 22 Apr 2020 20:08:15 -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=yUnbRtoApjh+Xm93rvjm8XxUXGcb+K4NFixHNRRWZCk=; b=ZsjvSjfZRgW5ycKonjPxsOZbYd18Jzt7FeAviIlB/ynoslO23+tstQXFroa32HuTqj AFFWPDNQmjEDiUDx2vGIP01O/1HuYSoQ0/JkOakAbNq6B6W0ZPG2jESmP360TMlw2rBP dGU1omt9ut9k88DRYkq3EXeP9tlMY/cUZiwVTP5WTCr2IzkHTaeZnGvpSkHO8RqVQkOD iiSq69bu/tKtn0FjxN6H73Mw2bU+P/i6+mlorzUdgbYDu26me49um3RYBmZAk+j0sO8r K7DUTAAHZBmzShlleSX1R7Utb8JYC2VDszTO/BosnW4CwXZlDvQxVTD0MN+MlNTxNItz TuWA== 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=yUnbRtoApjh+Xm93rvjm8XxUXGcb+K4NFixHNRRWZCk=; b=UP0Kd9LVZKA7+M6hkMYSKX7ED6jB7WbzBWW+efGtGqjteAsIZah1d6C/vFmmH+rD43 Dopvy8GJB90CoaGSeEbJAL4jAA2gcf9iiugtEhgDRvgv/NvOph/FS1WRxlPGJIXE1YPQ eJMgriqwxgNQdv/xGhhlPoOOObUENEApDFN165abarojfk1/gda3vWjbKtfyY1na7z9b //7Qpf9X3JVjwXgV9+LAYrC5/yWqaJQYs0wG7fjnVKjwOqjNO3y1dTTh2OiYUfCC7YNX bz5MIglLFYkrgWQiAzjn3UbpYqFPsIdMD/2JJywcr0v8SaEt2U64G+fLPQryQ7EVZyOi S4qg== X-Gm-Message-State: AGi0PubmW1sKFnlvsLUHVBuuaBTRqYtV4HWfFiMZIw5XD6zeJprqTl/c hsYn1cn2Th0yyqpSgaUa8eLZA7w6 X-Google-Smtp-Source: APiQypLEksX9tS84zi8umgHX8bnvI+FayoqQIYLI3leQqgkjdmgGrVzEti5UFtnXuwhPy5LM1LNzfw== X-Received: by 2002:adf:c442:: with SMTP id a2mr2284701wrg.110.1587611294475; Wed, 22 Apr 2020 20:08:14 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id m1sm1497733wro.64.2020.04.22.20.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 20:08:13 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Apr 2020 05:07:38 +0200 Message-Id: <20200423030741.12158-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200423030741.12158-1-andreas.rheinhardt@gmail.com> References: <20200423030741.12158-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/11] 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 3b1b447d8a..088eeabf2d 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3556,13 +3556,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);