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 {