mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Check if two consecutive MPEG audio frames are consistent.
This fixes reading the audio properties of some MP3 files reported by a Kodi user. This is basically the same check as FFmpeg does.
This commit is contained in:
parent
1254534ed4
commit
3dc873b7d0
@ -307,10 +307,24 @@ void MPEG::Header::parse(File *file, long offset, bool checkLength)
|
||||
if(checkLength) {
|
||||
|
||||
file->seek(offset + d->frameLength);
|
||||
const ByteVector nextSynch = file->readBlock(2);
|
||||
const ByteVector nextData = file->readBlock(4);
|
||||
|
||||
if(nextSynch.size() < 2 || !firstSyncByte(nextSynch[0]) || !secondSynchByte(nextSynch[1])) {
|
||||
debug("MPEG::Header::parse() -- Calculated frame length did not match the actual length.");
|
||||
if(nextData.size() < 4) {
|
||||
debug("MPEG::Header::parse() -- Could not read the next frame header.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The MPEG versions, layers and sample rates of the two frames should be
|
||||
// consistent. Otherwise, we assume that either or both of the frames are
|
||||
// broken.
|
||||
|
||||
const unsigned int HeaderMask = 0xfffe0c00;
|
||||
|
||||
const unsigned int header = data.toUInt(0, true) & HeaderMask;
|
||||
const unsigned int nextHeader = nextData.toUInt(0, true) & HeaderMask;
|
||||
|
||||
if(header != nextHeader) {
|
||||
debug("MPEG::Header::parse() -- The next frame was not consistent with this frame.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user