mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Make FLAC::File tolerant to zero-sized padding blocks.
This commit is contained in:
parent
e90b5e5f2f
commit
6f944b0291
@ -421,9 +421,15 @@ void FLAC::File::scan()
|
||||
isLastBlock = (header[0] & 0x80) != 0;
|
||||
length = header.toUInt(1U, 3U);
|
||||
|
||||
ByteVector data = readBlock(length);
|
||||
if(data.size() != length || length == 0) {
|
||||
debug("FLAC::File::scan() -- FLAC stream corrupted");
|
||||
if(length == 0 && blockType != MetadataBlock::Padding) {
|
||||
debug("FLAC::File::scan() -- Zero-sized metadaba block found");
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const ByteVector data = readBlock(length);
|
||||
if(data.size() != length) {
|
||||
debug("FLAC::File::scan() -- Failed to read a metadata block");
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
@ -446,7 +452,7 @@ void FLAC::File::scan()
|
||||
block = picture;
|
||||
}
|
||||
else {
|
||||
debug("FLAC::File::scan() -- invalid picture found, discarting");
|
||||
debug("FLAC::File::scan() -- invalid picture found, discarding");
|
||||
delete picture;
|
||||
}
|
||||
}
|
||||
|
BIN
tests/data/zero-sized-padding.flac
Normal file
BIN
tests/data/zero-sized-padding.flac
Normal file
Binary file not shown.
@ -25,6 +25,7 @@ class TestFLAC : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testSaveMultipleValues);
|
||||
CPPUNIT_TEST(testDict);
|
||||
CPPUNIT_TEST(testInvalid);
|
||||
CPPUNIT_TEST(testZeroSizedPadding);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -255,6 +256,14 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.properties().size());
|
||||
}
|
||||
|
||||
void testZeroSizedPadding()
|
||||
{
|
||||
ScopedFileCopy copy("zero-sized-padding", ".flac");
|
||||
|
||||
FLAC::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
|
||||
|
Loading…
Reference in New Issue
Block a user