From 40bf52e70f6e913d7082fc675b2627eb2ce408f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Tue, 10 Jan 2012 17:18:20 +0100 Subject: [PATCH] Reverse the version check, similarly to what mp4v2 does --- taglib/mp4/mp4properties.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index 5dc87673..d2d04167 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -90,15 +90,24 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) file->seek(mdhd->offset); data = file->readBlock(mdhd->length); - if(data[8] == 0) { - unsigned int unit = data.mid(20, 4).toUInt(); - unsigned int length = data.mid(24, 4).toUInt(); - d->length = length / unit; - } - else { + uint version = data[8]; + if(version == 1) { + if (data.size() < 36 + 8) { + debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); + return; + } long long unit = data.mid(28, 8).toLongLong(); long long length = data.mid(36, 8).toLongLong(); - d->length = int(length / unit); + d->length = unit ? int(length / unit) : 0; + } + else { + if (data.size() < 24 + 4) { + debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); + return; + } + unsigned int unit = data.mid(20, 4).toUInt(); + unsigned int length = data.mid(24, 4).toUInt(); + d->length = unit ? length / unit : 0; } MP4::Atom *atom = trak->find("mdia", "minf", "stbl", "stsd"); -- 2.40.0