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;
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;
}
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;
}
}
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)
{
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);
bool
MP4::File::save()
{
+ if(!isValid())
+ return false;
+
return d->tag->save();
}