]> granicus.if.org Git - taglib/commitdiff
Ignore trailing non-data atoms when parsing MP4 covr atoms
authorLukáš Lalinský <lalinsky@gmail.com>
Fri, 2 Apr 2010 12:14:32 +0000 (12:14 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Fri, 2 Apr 2010 12:14:32 +0000 (12:14 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1110209 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/mp4/mp4tag.cpp
tests/data/covr-junk.m4a [new file with mode: 0644]
tests/test_mp4.cpp
tests/utils.h

index ecffbef411d5f6c05f69cfd681176091cb04e67c..f8acc87a38fb600486dfccc86b885bfe55e3fe8e 100644 (file)
@@ -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 (file)
index 0000000..ac80cb2
Binary files /dev/null and b/tests/data/covr-junk.m4a differ
index ce6f189749b6bc5ab19a8875f4b1dd9996950835..31ea60964c808753ef72a600f4866fb34759254b 100644 (file)
@@ -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);
index ad61d284710e15a312dd0cf516dffbbfc10e97c9..dece293f986cd325b0a34fd807df087d318cd833 100644 (file)
@@ -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;
 };