Make FLAC::File tolerant to zero-sized padding blocks.

This commit is contained in:
Tsuda Kageyu 2015-07-29 20:52:56 +09:00
parent e90b5e5f2f
commit 6f944b0291
3 changed files with 19 additions and 4 deletions

View File

@ -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;
}
}

Binary file not shown.

View File

@ -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);