Hi,
I am reporting an issue with parsing of APE tags. I am adding some pieces of code that I followed to find the problem.
Problem:
I have an MP3 file with ID3 and APE tags in it. The cover art is about 4MB. This is in APE and ID3 tag. When trying to play the file with VLC I get the following errors:
TagLib: String::prepare() - Unicode conversion error.
I also monitored the memory usage of VLC when playing this file and it went up to 500MB! Normally it is around 30MB when another MP3 file is being played with only ID3 tag (version not depended).
For normal PC, this is not a big issue as there is plenty of memory, but when playing the same file on embedded device, the player will eat app a lot of memory, which is very limited.
Possible issue:
I looked around the source code of TagLib and the problem occurred when doing the following:
TagLib::FileRef val(filename) (filename is the mp3 file)
This one will create a file with
FileRefPrivate(create(fileName, readAudioProperties, audioPropertiesStyle))
The create method will call
MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
The constructor will call
void MPEG::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
Inside this method findAPE() will be called and then a new APE tag will be created
d->tag.set(APEIndex, new APE::Tag(this, d->APEFooterLocation));
The constructor of the APE tag will call read method and this one will call parse(...)
parse(d->file->readBlock(d->footer.tagSize() - Footer::size()));
The parse method will loop until the condition is true
for(uint i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) {
APE::Item item;
item.parse(data.mid(pos));
d->itemListMap.insert(item.key().upper(), item);
pos += item.size();
}
The item.parse(...) will create strings with large sizes (same as the footer).
By looping multiple times, the d->itemListMap.insert(item.key().upper(), item); will grow a lot until the end of loop.
From the documentation I saw that APE tag should not be bigger that 8K. JPEG's are suggested to be put as links i.s.o in the tag.
As we know, users will not follow such rules. (ID3 tag could have 256MB of header).
Is it feasible to add a check on the size of the APE tag to not load APE tags bigger that 8K?
If the file is needed for debugging, please let me know. Or you can use MP3Tag program to attach a 5MB image to your MP3s and you will have the same problem.