]> granicus.if.org Git - taglib/commitdiff
Be more paranoid about checking MP4 files
authorLukáš Lalinský <lalinsky@gmail.com>
Mon, 14 Dec 2009 18:42:40 +0000 (18:42 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Mon, 14 Dec 2009 18:42:40 +0000 (18:42 +0000)
To consider something a valid MP4 file, it must have a 'moov' atom. Otherwise
it's marked as invalid and we won't try to read/write tags.

CCBUG:216819

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1062426 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/mp4/mp4file.cpp
tests/test_mp4.cpp

index 3c996d1b4859e60bb1a3f5ead66f9d8ae94ef495..21a5429b21a31d7518272ca780ae4f59cc710172 100644 (file)
@@ -113,6 +113,13 @@ MP4::File::read(bool readProperties, Properties::ReadStyle audioPropertiesStyle)
     return;
   }
 
+  // must have a moov atom, otherwise consider it invalid
+  MP4::Atom *moov = d->atoms->find("moov");
+  if(!moov) {
+    setValid(false);
+    return;
+  }
+
   d->tag = new Tag(this, d->atoms);
   if(readProperties) {
     d->properties = new Properties(this, d->atoms, audioPropertiesStyle);
index a5b301bc5c0ab1273383533afab6909a1c13e5fe..ce6f189749b6bc5ab19a8875f4b1dd9996950835 100644 (file)
@@ -16,6 +16,7 @@ class TestMP4 : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE(TestMP4);
   CPPUNIT_TEST(testProperties);
   CPPUNIT_TEST(testFreeForm);
+  CPPUNIT_TEST(testCheckValid);
   CPPUNIT_TEST(testUpdateStco);
   CPPUNIT_TEST(testSaveExisingWhenIlstIsLast);
   CPPUNIT_TEST(test64BitAtom);
@@ -36,6 +37,14 @@ public:
     CPPUNIT_ASSERT_EQUAL(16, ((MP4::Properties *)f.audioProperties())->bitsPerSample());
   }
 
+  void testCheckValid()
+  {
+    MP4::File f("data/empty.aiff");
+    CPPUNIT_ASSERT(!f.isValid());
+    MP4::File f2("data/has-tags.m4a");
+    CPPUNIT_ASSERT(f2.isValid());
+  }
+
   void testUpdateStco()
   {
     ScopedFileCopy copy("no-tags", ".3g2");