// Handle Pictures separately
if(entry.startsWith("METADATA_BLOCK_PICTURE=")) {
- // Decode base64 picture data
- ByteVector picturedata = ByteVector::fromBase64(entry.mid(23));
-
- if(picturedata.size() == 0) {
- debug("Empty picture data. Discarding content");
- continue;
+ // 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");
}
-
- FLAC::Picture * picture = new FLAC::Picture();
-
- if(picture->parse(picturedata))
- d->pictureList.append(picture);
- else
- debug("Unable to parse METADATA_BLOCK_PICTURE. Discarding content.");
}
- else if (entry.startsWith("COVERART=")) {
- // Decode base64 picture data
- ByteVector picturedata = ByteVector::fromBase64(entry.mid(9));
+ // Handle old picture standard
+ if (entry.startsWith("COVERART=")) {
- if (picturedata.size() == 0) {
- debug("Empty coverart data. Discaring content");
- continue;
- }
+ if((entry.size() - 9) > 3 && ((entry.size() - 9) % 4) == 0) {
- // 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 {
+ // 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);
- // Check for field separator
- int sep = entry.find('=');
- if (sep < 1) {
- debug("Discarding invalid comment field.");
- continue;
+ // continue to next field
+ continue;
+ }
+ else {
+ debug("Failed to decode base64 encoded data");
+ }
+ }
+ else {
+ debug("Invalid base64 encoded data");
}
+ }
- // 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);
+ // Check for field separator
+ int sep = entry.find('=');
+ if (sep < 1) {
+ debug("Discarding invalid comment field.");
+ 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);
}
}