mirror of
https://github.com/taglib/taglib.git
synced 2025-07-26 08:54:30 -04:00
Fix handling of lowercase 'metadata_block_picture' fields in Vorbis comments.
Also refactored some redundant code for parsing pictures.
This commit is contained in:
@ -447,85 +447,69 @@ void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
const unsigned int commentLength = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
ByteVector entry = data.mid(pos, commentLength);
|
||||
|
||||
const ByteVector entry = data.mid(pos, commentLength);
|
||||
pos += commentLength;
|
||||
|
||||
// Don't go past data end
|
||||
|
||||
if(pos > data.size())
|
||||
break;
|
||||
|
||||
// Handle Pictures separately
|
||||
if(entry.startsWith("METADATA_BLOCK_PICTURE=")) {
|
||||
|
||||
// We need base64 encoded data including padding
|
||||
if((entry.size() - 23) > 3 && ((entry.size() - 23) % 4) == 0) {
|
||||
|
||||
// Decode base64 picture data
|
||||
ByteVector picturedata = ByteVector::fromBase64(entry.mid(23));
|
||||
if(picturedata.size()) {
|
||||
|
||||
// Decode Flac Picture
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
if(picture->parse(picturedata)) {
|
||||
|
||||
d->pictureList.append(picture);
|
||||
|
||||
// continue to next field
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
delete picture;
|
||||
debug("Failed to decode FlacPicture block");
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Failed to decode base64 encoded data");
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Invalid base64 encoded data");
|
||||
}
|
||||
}
|
||||
|
||||
// Handle old picture standard
|
||||
if(entry.startsWith("COVERART=")) {
|
||||
|
||||
if((entry.size() - 9) > 3 && ((entry.size() - 9) % 4) == 0) {
|
||||
|
||||
// Decode base64 picture data
|
||||
ByteVector picturedata = ByteVector::fromBase64(entry.mid(9));
|
||||
if (picturedata.size()) {
|
||||
|
||||
// Assume it's some type of image file
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
picture->setData(picturedata);
|
||||
picture->setMimeType("image/");
|
||||
picture->setType(FLAC::Picture::Other);
|
||||
d->pictureList.append(picture);
|
||||
|
||||
// continue to next field
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
debug("Failed to decode base64 encoded data");
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Invalid base64 encoded data");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for field separator
|
||||
int sep = entry.find('=');
|
||||
|
||||
const int sep = entry.find('=');
|
||||
if(sep < 1) {
|
||||
debug("Discarding invalid comment field.");
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Separator not found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse key and value
|
||||
String key = String(entry.mid(0, sep), String::UTF8);
|
||||
String value = String(entry.mid(sep + 1), String::UTF8);
|
||||
addField(key, value, false);
|
||||
// Parse the key
|
||||
|
||||
const String key = String(entry.mid(0, sep), String::UTF8).upper();
|
||||
if(!checkKey(key)) {
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Invalid key.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key == "METADATA_BLOCK_PICTURE" || key == "COVERART") {
|
||||
|
||||
// Handle Pictures separately
|
||||
|
||||
const ByteVector picturedata = ByteVector::fromBase64(entry.mid(sep + 1));
|
||||
if(picturedata.isEmpty()) {
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Invalid base64 data");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key[0] == L'M') {
|
||||
|
||||
// Decode FLAC Picture
|
||||
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
if(picture->parse(picturedata)) {
|
||||
d->pictureList.append(picture);
|
||||
}
|
||||
else {
|
||||
delete picture;
|
||||
debug("Ogg::XiphComment::parse() - Failed to decode FLAC Picture block");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Assume it's some type of image file
|
||||
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
picture->setData(picturedata);
|
||||
picture->setMimeType("image/");
|
||||
picture->setType(FLAC::Picture::Other);
|
||||
d->pictureList.append(picture);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Parse the text
|
||||
|
||||
addField(key, String(entry.mid(sep + 1), String::UTF8), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user