From: Lukáš Lalinský Date: Fri, 2 Apr 2010 12:14:32 +0000 (+0000) Subject: Ignore trailing non-data atoms when parsing MP4 covr atoms X-Git-Tag: v1.6.2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=394366860380d20cd1cbf60975d66d89c256d971;p=taglib Ignore trailing non-data atoms when parsing MP4 covr atoms git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1110209 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index ecffbef4..f8acc87a 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -209,7 +209,7 @@ MP4::Tag::parseCovr(MP4::Atom *atom, TagLib::File *file) int flags = data.mid(pos + 8, 4).toUInt(); if(name != "data") { debug("MP4: Unexpected atom \"" + name + "\", expecting \"data\""); - return; + break; } if(flags == MP4::CoverArt::PNG || flags == MP4::CoverArt::JPEG) { value.append(MP4::CoverArt(MP4::CoverArt::Format(flags), diff --git a/tests/data/covr-junk.m4a b/tests/data/covr-junk.m4a new file mode 100644 index 00000000..ac80cb29 Binary files /dev/null and b/tests/data/covr-junk.m4a differ diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index ce6f1897..31ea6096 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -23,6 +23,7 @@ class TestMP4 : public CppUnit::TestFixture CPPUNIT_TEST(testGnre); CPPUNIT_TEST(testCovrRead); CPPUNIT_TEST(testCovrWrite); + CPPUNIT_TEST(testCovrRead2); CPPUNIT_TEST_SUITE_END(); public: @@ -157,6 +158,7 @@ public: { MP4::File *f = new MP4::File("data/gnre.m4a"); CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f->tag()->genre()); + delete f; } void testCovrRead() @@ -169,6 +171,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + delete f; } void testCovrWrite() @@ -197,6 +200,19 @@ public: delete f; } + void testCovrRead2() + { + MP4::File *f = new MP4::File("data/covr-junk.m4a"); + CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr")); + MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + delete f; + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4); diff --git a/tests/utils.h b/tests/utils.h index ad61d284..dece293f 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -38,14 +38,16 @@ inline void deleteFile(const string &filename) class ScopedFileCopy { public: - ScopedFileCopy(const string &filename, const string &ext) + ScopedFileCopy(const string &filename, const string &ext, bool deleteFile=true) { + m_deleteFile = deleteFile; m_filename = copyFile(filename, ext); } ~ScopedFileCopy() { - deleteFile(m_filename); + if(m_deleteFile) + deleteFile(m_filename); } string fileName() @@ -54,5 +56,6 @@ public: } private: + bool m_deleteFile; string m_filename; };