Fix a segfault when reading faulty Ogg/FLAC files.

This commit is contained in:
Tsuda Kageyu 2015-01-01 19:54:17 +09:00
parent 79b7c14129
commit 5ebb2ece80
3 changed files with 14 additions and 2 deletions

View File

@ -103,7 +103,7 @@ PropertyMap Ogg::FLAC::File::properties() const
PropertyMap Ogg::FLAC::File::setProperties(const PropertyMap &properties)
{
return d->comment->setProperties(properties);
}
}
Properties *Ogg::FLAC::File::audioProperties() const
{
@ -233,7 +233,12 @@ void Ogg::FLAC::File::scan()
}
header = metadataHeader.mid(0,4);
header = metadataHeader.mid(0, 4);
if(header.size() < 4) {
debug("Ogg::FLAC::File::scan() -- Invalid Ogg/FLAC metadata header");
return;
}
// Header format (from spec):
// <1> Last-metadata-block flag
// <7> BLOCK_TYPE

BIN
tests/data/segfault.oga Normal file

Binary file not shown.

View File

@ -15,6 +15,7 @@ class TestOggFLAC : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestOggFLAC);
CPPUNIT_TEST(testFramingBit);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST_SUITE_END();
public:
@ -39,6 +40,12 @@ public:
delete f;
}
void testFuzzedFile()
{
Ogg::FLAC::File f(TEST_FILE_PATH_C("segfault.oga"));
CPPUNIT_ASSERT(!f.isValid());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestOggFLAC);