From 9679b081209c980209ff79c3e676ce2a78c7f990 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Thu, 9 Nov 2023 20:59:47 +0100 Subject: [PATCH] Verify type of ID3v2 frames used for complex properties (#1173) A frame with ID "APIC" is not guaranteed to be an AttachedPictureFrame, it can also be an invalid UnknownFrame with ID "APIC". Check the types of the frames before accessing them. --- taglib/mpeg/id3v2/id3v2tag.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 3dc28011..689970ec 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -472,26 +472,28 @@ List ID3v2::Tag::complexProperties(const String &key) const if(uppercaseKey == "PICTURE") { const FrameList pictures = d->frameListMap.value("APIC"); for(const Frame *frame : pictures) { - auto picture = static_cast(frame); - VariantMap property; - property.insert("data", picture->picture()); - property.insert("mimeType", picture->mimeType()); - property.insert("description", picture->description()); - property.insert("pictureType", - AttachedPictureFrame::typeToString(picture->type())); - properties.append(property); + if(auto picture = dynamic_cast(frame)) { + VariantMap property; + property.insert("data", picture->picture()); + property.insert("mimeType", picture->mimeType()); + property.insert("description", picture->description()); + property.insert("pictureType", + AttachedPictureFrame::typeToString(picture->type())); + properties.append(property); + } } } else if(uppercaseKey == "GENERALOBJECT") { const FrameList geobs = d->frameListMap.value("GEOB"); for(const Frame *frame : geobs) { - auto geob = static_cast(frame); - VariantMap property; - property.insert("data", geob->object()); - property.insert("mimeType", geob->mimeType()); - property.insert("description", geob->description()); - property.insert("fileName", geob->fileName()); - properties.append(property); + if(auto geob = dynamic_cast(frame)) { + VariantMap property; + property.insert("data", geob->object()); + property.insert("mimeType", geob->mimeType()); + property.insert("description", geob->description()); + property.insert("fileName", geob->fileName()); + properties.append(property); + } } } return properties;