]> granicus.if.org Git - taglib/commitdiff
A little more complex checking for broken files
authorLukáš Lalinský <lalinsky@gmail.com>
Sat, 31 Oct 2009 08:59:40 +0000 (08:59 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Sat, 31 Oct 2009 08:59:40 +0000 (08:59 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1042948 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/mp4/mp4atom.cpp
taglib/mp4/mp4file.cpp
taglib/mp4/mp4file.h

index 25007946b3d0fbc4c7c7954b00fa064d6009c3b6..6d86a6e5798f7a6f159db11260a0c3d6bddbd24c 100644 (file)
@@ -47,7 +47,7 @@ MP4::Atom::Atom(File *file)
   if (header.size() != 8) {
     // The atom header must be 8 bytes long, otherwise there is either
     // trailing garbage or the file is truncated
-    debug("MP4: Expected 8 bytes of atom header");
+    debug("MP4: Couldn't read 8 bytes of data for atom header");
     length = 0;
     file->seek(0, File::End);
     return;
@@ -83,7 +83,10 @@ MP4::Atom::Atom(File *file)
         file->seek(4, File::Current);
       }
       while(file->tell() < offset + length) {
-        children.append(new MP4::Atom(file));
+        MP4::Atom *child = new MP4::Atom(file);
+        children.append(child);
+        if (child->length == 0)
+          return;
       }
       return;
     }
@@ -150,7 +153,10 @@ MP4::Atoms::Atoms(File *file)
   long end = file->tell();
   file->seek(0);
   while(file->tell() + 8 <= end) {
-    atoms.append(new MP4::Atom(file));
+    MP4::Atom *atom = new MP4::Atom(file);
+    atoms.append(atom);
+    if (atom->length == 0)
+      break;
   }
 }
 
index 3165256c4a58a19365a08f7f8d576ea97854eacc..3c996d1b4859e60bb1a3f5ead66f9d8ae94ef495 100644 (file)
@@ -89,6 +89,18 @@ MP4::File::audioProperties() const
   return d->properties;
 }
 
+bool
+MP4::File::checkValid(const MP4::AtomList &list)
+{
+  for(uint i = 0; i < list.size(); i++) {
+    if(list[i]->length == 0)
+      return false;
+    if(!checkValid(list[i]->children))
+      return false;
+  }
+  return true;
+}
+
 void
 MP4::File::read(bool readProperties, Properties::ReadStyle audioPropertiesStyle)
 {
@@ -96,6 +108,11 @@ MP4::File::read(bool readProperties, Properties::ReadStyle audioPropertiesStyle)
     return;
 
   d->atoms = new Atoms(this);
+  if (!checkValid(d->atoms->atoms)) {
+    setValid(false);
+    return;
+  }
+
   d->tag = new Tag(this, d->atoms);
   if(readProperties) {
     d->properties = new Properties(this, d->atoms, audioPropertiesStyle);
@@ -105,6 +122,9 @@ MP4::File::read(bool readProperties, Properties::ReadStyle audioPropertiesStyle)
 bool
 MP4::File::save()
 {
+  if(!isValid())
+    return false;
+
   return d->tag->save();
 }
 
index 0c09c04e458c1f45319d7a494a66f924cac4d52b..333551a9036309141d658f8e6e131a0e5fa2e503 100644 (file)
@@ -90,6 +90,7 @@ namespace TagLib {
     private:
 
       void read(bool readProperties, Properties::ReadStyle audioPropertiesStyle);
+      bool checkValid(const MP4::AtomList &list);
 
       class FilePrivate;
       FilePrivate *d;