A little more complex checking for broken files

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1042948 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský 2009-10-31 08:59:40 +00:00
parent 5a40a45cc5
commit f1abbf33f2
3 changed files with 30 additions and 3 deletions

View 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;
}
}

View 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();
}

View 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;