diff --git a/3rdparty/taglib/ogg/opus/opusproperties.cpp b/3rdparty/taglib/ogg/opus/opusproperties.cpp index 0d7cfa78e..bbc40ef9d 100644 --- a/3rdparty/taglib/ogg/opus/opusproperties.cpp +++ b/3rdparty/taglib/ogg/opus/opusproperties.cpp @@ -163,8 +163,14 @@ void Opus::Properties::read(File *file) if(frameCount > 0) { const double length = frameCount * 1000.0 / 48000.0; + long fileLengthWithoutOverhead = file->length(); + // Ignore the two mandatory header packets, see "3. Packet Organization" + // in https://tools.ietf.org/html/rfc7845.html + for (unsigned int i = 0; i < 2; ++i) { + fileLengthWithoutOverhead -= file->packet(i).size(); + } d->length = static_cast(length + 0.5); - d->bitrate = static_cast(file->length() * 8.0 / length + 0.5); + d->bitrate = static_cast(fileLengthWithoutOverhead * 8.0 / length + 0.5); } } else { diff --git a/3rdparty/taglib/ogg/speex/speexfile.cpp b/3rdparty/taglib/ogg/speex/speexfile.cpp index 17c7d263b..65d65f8a1 100644 --- a/3rdparty/taglib/ogg/speex/speexfile.cpp +++ b/3rdparty/taglib/ogg/speex/speexfile.cpp @@ -131,6 +131,7 @@ void Speex::File::read(bool readProperties) if(!speexHeaderData.startsWith("Speex ")) { debug("Speex::File::read() -- invalid Speex identification header"); + setValid(false); return; } diff --git a/3rdparty/taglib/ogg/speex/speexproperties.cpp b/3rdparty/taglib/ogg/speex/speexproperties.cpp index a34c043b5..12d5e1c4e 100644 --- a/3rdparty/taglib/ogg/speex/speexproperties.cpp +++ b/3rdparty/taglib/ogg/speex/speexproperties.cpp @@ -182,8 +182,14 @@ void Speex::Properties::read(File *file) if(frameCount > 0) { const double length = frameCount * 1000.0 / d->sampleRate; + long fileLengthWithoutOverhead = file->length(); + // Ignore the two header packets, see "Ogg file format" in + // https://www.speex.org/docs/manual/speex-manual/node8.html + for (unsigned int i = 0; i < 2; ++i) { + fileLengthWithoutOverhead -= file->packet(i).size(); + } d->length = static_cast(length + 0.5); - d->bitrate = static_cast(file->length() * 8.0 / length + 0.5); + d->bitrate = static_cast(fileLengthWithoutOverhead * 8.0 / length + 0.5); } } else { diff --git a/3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp b/3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp index b72e4be9f..512e04967 100644 --- a/3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp +++ b/3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp @@ -188,9 +188,14 @@ void Vorbis::Properties::read(File *file) if(frameCount > 0) { const double length = frameCount * 1000.0 / d->sampleRate; - + long fileLengthWithoutOverhead = file->length(); + // Ignore the three initial header packets, see "1.3.1. Decode Setup" in + // https://xiph.org/vorbis/doc/Vorbis_I_spec.html + for (unsigned int i = 0; i < 3; ++i) { + fileLengthWithoutOverhead -= file->packet(i).size(); + } d->length = static_cast(length + 0.5); - d->bitrate = static_cast(file->length() * 8.0 / length + 0.5); + d->bitrate = static_cast(fileLengthWithoutOverhead * 8.0 / length + 0.5); } } else { diff --git a/3rdparty/taglib/riff/rifffile.cpp b/3rdparty/taglib/riff/rifffile.cpp index 5add8322b..f41fb370a 100644 --- a/3rdparty/taglib/riff/rifffile.cpp +++ b/3rdparty/taglib/riff/rifffile.cpp @@ -325,9 +325,20 @@ void RIFF::File::read() if(offset & 1) { seek(offset); const ByteVector iByte = readBlock(1); - if(iByte.size() == 1 && iByte[0] == '\0') { - chunk.padding = 1; - offset++; + if(iByte.size() == 1) { + bool skipPadding = iByte[0] == '\0'; + if(!skipPadding) { + // Padding byte is not zero, check if it is good to ignore it + const ByteVector fourCcAfterPadding = readBlock(4); + if(isValidChunkName(fourCcAfterPadding)) { + // Use the padding, it is followed by a valid chunk name. + skipPadding = true; + } + } + if(skipPadding) { + chunk.padding = 1; + offset++; + } } }