From patchwork Thu Mar 26 00:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18404 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a0c:ab15:0:0:0:0:0 with SMTP id h21csp280697qvb; Wed, 25 Mar 2020 17:42:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtjJ4spn5tiYbs2iPtDPM/MDIXRI34ymH/gnxvorGceYyAHSJUBFYdz5ZPnLhSDoaRElnUZ X-Received: by 2002:a05:6402:504:: with SMTP id m4mr5020237edv.367.1585183324172; Wed, 25 Mar 2020 17:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585183324; cv=none; d=google.com; s=arc-20160816; b=mKP+bykWqDDiIQOOY52fwSE9RQuAxPvfylGdsPfYxsWMph7Ttan1Sa8B8ubyvkOUnG LF+Qn5pMViY0Z6y2KQAQUwNUtcJf0N+QE6J1cRagRqp8BrcwkDF7cplbR2TTA077Dv3u nUfRy5vzW+GG5dCWB4iAmXuavu46Svx3qZkEzYfmmLkQiKc03f7skzVrmd+C2ifEGa9r mSWYj5NDFZcC/VlYJy7al7l1Ei9rmUQ2dCf5O69S2bAoa2W5QGvO/jSmsTR04VgTyE2l bCQWoKfgysqyAeu5PXhcOqgEGjJ11mIPAToX3rCqS3d6cMaKlv+2RM8GMcccoNfqomo1 GyEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=5UT0+a16uoWubtbV41Jw21Lu0ClcvV7o2A+/eOp4paE=; b=Sn52boC2ee5O296t3mblZEKsT61kHmJRZPa2gfA3CYyVeKyGCOeO/KVZD0fgsnirMm LtO6sv+OOBYCvGJt3UJHM7kt+MUyz5wkv4Vu4vbE9+sJ/8jlNEU7MA6Tlv4+kt/0SI1c 4Z4hKx5ZjNZskJmHAMbmXwzg/YAN6j6yZVifPFzIFDLhjh2WdVyQtwClAa0db0307zV5 gUQTCdGySKPDwTxmG70b1N/rPLPTNnSXc0hUoJyiqfuxZpJz62EYr0qotTSobHabhHg9 XeHQagYZrzFc4HJ9DUwxsjI7/LBVYMGflAHepzkEPkY0UaKj/ZcS2xJb6+alqGlpjZlD C2hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=j27oO7Vw; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x14si344305eds.0.2020.03.25.17.42.03; Wed, 25 Mar 2020 17:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=j27oO7Vw; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD0BC68B474; Thu, 26 Mar 2020 02:42:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7729F68AF83 for ; Thu, 26 Mar 2020 02:41:55 +0200 (EET) Received: by mail-wm1-f53.google.com with SMTP id 26so6193006wmk.1 for ; Wed, 25 Mar 2020 17:41:55 -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:mime-version :content-transfer-encoding; bh=Y6hwL4lF99mO+jZEBuIYQVkEvXO1fSCCrsD7L8xYe3c=; b=j27oO7VwcSJR18k20rV+O97HXbvMKJII23Y/uSoxdzlknsECUvdo63tUCTG7AFVyAX qrq6DtE1D933N5fgehJo2oZIluFHJJlSMTN207x0MyVQ2VFJYrhrVordIFAS+676IzSV AO6QPaoEUQGiFW2z1ki0J5XR/xlD3k1X9D4hxn+/asAwY8q26egbF/yVvsWOCEPxzf0b 5d9L/D7dq/CTIRTGtuFK45TNMcyjUqvXNVokfc8gQq7CdXUnxNPkV4aZzQRaCDI/OLM5 SWT30849GQIFLAKzem0WqySGmjuDgkrF6FA1Ym5Z3wV2IbHpudkfNfcn1wOd9x+fEmA1 EkOA== 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:mime-version :content-transfer-encoding; bh=Y6hwL4lF99mO+jZEBuIYQVkEvXO1fSCCrsD7L8xYe3c=; b=qoEPBcbJC4ul8WtK+L6bUrfCareKgOMzbec3IlkG7QVQDSElVA+qUSAfVs4OH9xZxe cITQePdhceAV0i5BevUZs601XdCuzD4w6jAR+8fhX9UOVtZgGBaT1tx7fbpHjeRMiSJw qg9xAcNwDtrT7s7uSgCZW9zPPH0BU0ais/6qpu+Y/7gyXZYajD9XHzYsMP1T4DUdyQgN Nw9UfWNYOSAT/Vv78vOFkZonzhTyv+71Batnh+zNsf4x3cLbEZr770/2rtyVvjMgMFWz xNLNh7qfdc3TCcc+Teu28YjEaCB5DtERph9pWd6PTb1YwqeJAdXZyDEZP4/WNCNcrzQE qxhg== X-Gm-Message-State: ANhLgQ1/oRoQsiYVuJj8M0Zjc3yd8IJ7imttidIoQrnr0WJNxjfjC5yB iPIAIeGJie1DuqLIrGvpRCuyxdu/ X-Received: by 2002:a05:600c:3cb:: with SMTP id z11mr270880wmd.94.1585183314502; Wed, 25 Mar 2020 17:41:54 -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.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 17:41:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Mar 2020 01:41:42 +0100 Message-Id: <20200326004144.26758-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/matroskadec: Don't discard the upper 32bits of TrackNumber 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" X-TUID: VjyOYIRp6qYC Content-Length: 1938 Signed-off-by: Andreas Rheinhardt --- This has already been sent in [1]; I'm resending it because it fits here. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254841.html libavformat/matroskadec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4d7fdab99f..6425973954 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1545,7 +1545,7 @@ static int matroska_probe(const AVProbeData *p) } static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska, - int num) + uint64_t num) { MatroskaTrack *tracks = matroska->tracks.elem; int i; @@ -1554,7 +1554,7 @@ static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska, if (tracks[i].num == num) return &tracks[i]; - av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num); + av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %"PRIu64"\n", num); return NULL; } From patchwork Thu Mar 26 00:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18401 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 C73FC4482A4 for ; Thu, 26 Mar 2020 02:42:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B1CDE68B515; Thu, 26 Mar 2020 02:42:15 +0200 (EET) 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 8F030689C6C for ; Thu, 26 Mar 2020 02:42:09 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id b2so5738754wrj.10 for ; Wed, 25 Mar 2020 17:42:09 -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=wPmw1lzZ0lmoGM3EB8u4VOYVOMh5r+DcvQZU1TnHoZo=; b=BXL4+piR/VZv8CycdoM1MijS9wMqlHk7kMX+l93lC7G6tm7jcGOSB+09yhsiUZyxMv pzINcLASydsxV09k8AmAKJ6BUVHEc7a5JnbikdQUVJ/aIEMQW3T+vy0zJgVgOZi3Aj9y toV3buvRsSpiVpX8JnEFePH39ATSjE/IY7DD6eFS452eGahXTEUpBroVQbaUUa3c9IM8 ytmlf+1tVj1kNnMH5/kA4cOWJtD0+/k2jA8y/EhintIClluRnEN9jzRxRr74FjRfSrNi OQPpF7IsYpGFPZQBtb0/Mi41PvHLCEtjrq8jfU5HJUnC7E7hH3zow1ejB9iIo3gS/WBM Dkdw== 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=wPmw1lzZ0lmoGM3EB8u4VOYVOMh5r+DcvQZU1TnHoZo=; b=L39kZIMbSm/LFJ00qq0GvNbaYP5oQpkdjcksdfYt8dQjRua4evYZuf+XpmhCd6eCYX QTxzdsSbp7DbKWFKKy82e3L6c6VimlylqcoghVZFx3KoYEoL7nW6jSlUtB76xBu4cJdm PiGk4VCWZ9TiKFGrR3sVy1adX25hBpHh5kSrGF2PI6kGz8uSe9lv9MukzhZioZ2wNIFs y/CJ3eG5rVmknES85EBGsUTd2syf0UpDv/iFcvNCGvrw04iV0w0SyUYGU+3HFGjpmrDe ng6Tz2trX941eIIH8Shp6OR33NuoN2qX9BTgn1zZfKazvH1fnKbmANBg4ZxTip+9+0RF DasA== X-Gm-Message-State: ANhLgQ3uEA5NMwuAhL9n3Ouq6deq01VKMHI6r5xpkO9PtMnT55iPtqn6 hq1hLSV6yyOAf8HK7wgxfqv/5CSl X-Google-Smtp-Source: ADFU+vtOgdnrKB8AVnCSmOBFuYEZt9MXZyCepyWag4lAYq4WE+ju1Mmcj6UuimXThjoDMeotxVJqxQ== X-Received: by 2002:adf:e584:: with SMTP id l4mr2181625wrm.388.1585183328484; Wed, 25 Mar 2020 17:42:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 17:42:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Mar 2020 01:41:43 +0100 Message-Id: <20200326004144.26758-2-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 2/3] avformat/matroskadec: Don't discard valid packets 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" A Block (meaning both a Block in a BlockGroup as well as a SimpleBlock) must have at least three bytes after the field containing the encoded TrackNumber. So a if there are <= 3 bytes, the Matroska demuxer would skip this block, believing it to be an empty, but valid Block. This might discard valid Blocks, even nonempty ones (namely if the track uses header stripping). And certain definitely spec-incompliant Blocks don't raise errors: Those with two or less bytes left after the encoded TrackNumber and those with three bytes left, but with flags indicating that the Block uses lacing (in which case there has to be further data describing the lacing). Furthermore, zero-sized packets were still possible because only the size of the last entry of a lace was checked. This commit fixes this. All spec-compliant Blocks are now returned to the caller, even those with a size of zero. This is in accordance with the documentation of av_read_frame(): "This function returns what is stored in the file, and does not validate that what is there are valid frames for the decoder". Signed-off-by: Andreas Rheinhardt --- mkclean can produce blocks where the payload has a size of zero before readding the removed header. E.g. it does this if a stream only has one frame in total (although in such a case the overhead of header removal compression is greater than the number of bytes saved in the Blocks); this can in particular happen with forced subtitle tracks with only one frame (which is how I noticed this). I am unsure what to do with size-zero packets; I don't know any Matroska Codec Mapping where this would be allowed. But there is nothing explicitly stating that they are generally illegal, so this commit returns them. The only thing I am certain is that stripping these packets away needs to happen after the content compressions have been reversed. libavformat/matroskadec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 6425973954..7aea13dda0 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2991,7 +2991,9 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, return 0; } - av_assert0(size > 0); + if (size <= 0) + return AVERROR_INVALIDDATA; + *laces = *data + 1; data += 1; size -= 1; @@ -3017,7 +3019,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, break; } } - if (size <= total) { + if (size < total) { return AVERROR_INVALIDDATA; } @@ -3064,7 +3066,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, } data += offset; size -= offset; - if (size <= total) { + if (size < total) { return AVERROR_INVALIDDATA; } lace_size[*laces - 1] = size - total; @@ -3524,8 +3526,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf av_log(matroska->ctx, AV_LOG_INFO, "Invalid stream %"PRIu64"\n", num); return AVERROR_INVALIDDATA; - } else if (size <= 3) - return 0; + } else if (size < 3) + return AVERROR_INVALIDDATA; st = track->stream; if (st->discard >= AVDISCARD_ALL) return res; 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);