From: Tsuda Kageyu Date: Wed, 29 Jul 2015 11:52:56 +0000 (+0900) Subject: Make FLAC::File tolerant to zero-sized padding blocks. X-Git-Tag: v1.10beta~63^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f944b02918c61528b977442c64c9b4bfd50078a;p=taglib Make FLAC::File tolerant to zero-sized padding blocks. --- diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index 823170aa..6df8f6b9 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -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; } } diff --git a/tests/data/zero-sized-padding.flac b/tests/data/zero-sized-padding.flac new file mode 100644 index 00000000..86ab8bf7 Binary files /dev/null and b/tests/data/zero-sized-padding.flac differ diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index f99a679a..164020a6 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -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);