From 2b09f9b53a149416e617360d2d8c77c7ffc8e9cf Mon Sep 17 00:00:00 2001 From: David Schalig Date: Wed, 28 Nov 2012 12:18:32 +0900 Subject: [PATCH] mkvparser: ignore 0-size elements in TrackEntry ParseTrackEntry handled MKVs with 0-sized EBML elements as malformed. Relaxing this and allow empty elements to allow parsing such MKV content. Change-Id: I7e430e9b2d177df7fe1e656546f63ee8673e784e --- mkvparser.cpp | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/mkvparser.cpp b/mkvparser.cpp index 43eb099..da12756 100644 --- a/mkvparser.cpp +++ b/mkvparser.cpp @@ -6533,35 +6533,29 @@ long Tracks::ParseTrackEntry( if (status < 0) //error return status; + if (size < 0) + return E_FILE_FORMAT_INVALID; + const long long start = pos; if (id == 0x60) // VideoSettings ID { - if (size <= 0) - return E_FILE_FORMAT_INVALID; - v.start = start; v.size = size; } else if (id == 0x61) // AudioSettings ID { - if (size <= 0) - return E_FILE_FORMAT_INVALID; - a.start = start; a.size = size; } else if (id == 0x2D80) // ContentEncodings ID { - if (size <= 0) - return E_FILE_FORMAT_INVALID; - e.start = start; e.size = size; } else if (id == 0x33C5) //Track UID { - if ((size <= 0) || (size > 8)) + if (size > 8) return E_FILE_FORMAT_INVALID; info.uid = 0; @@ -6637,28 +6631,28 @@ long Tracks::ParseTrackEntry( info.codecPrivate = NULL; info.codecPrivateSize = 0; - if (size <= 0) - return E_FILE_FORMAT_INVALID; - const size_t buflen = static_cast(size); - typedef unsigned char* buf_t; - - const buf_t buf = new (std::nothrow) unsigned char[buflen]; - - if (buf == NULL) - return -1; - - const int status = pReader->Read(pos, buflen, buf); - - if (status) + if (buflen) { - delete[] buf; - return status; - } + typedef unsigned char* buf_t; - info.codecPrivate = buf; - info.codecPrivateSize = buflen; + const buf_t buf = new (std::nothrow) unsigned char[buflen]; + + if (buf == NULL) + return -1; + + const int status = pReader->Read(pos, buflen, buf); + + if (status) + { + delete[] buf; + return status; + } + + info.codecPrivate = buf; + info.codecPrivateSize = buflen; + } } else if (id == 0x058688) //Codec Name {