[frameworks/kfilemetadata] src/extractors: taglib: Protect against UnknownFrame

Albert Astals Cid <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit dba1000068c5d94a805a0614d76cb575e02d8037 by Albert Astals Cid.
Committed on 27/07/2026 at 19:52.
Pushed by aacid into branch 'master'.

taglib: Protect against UnknownFrame

UnknownFrame is added to these lists when it is encrypted for example
(there are 3 cases in which FrameFactory::prepareFrameHeader returns {header,
false})

M  +22   -18   src/extractors/taglibextractor.cpp

https://invent.kde.org/frameworks/kfilemetadata/-/commit/dba1000068c5d94a805a0614d76cb575e02d8037

diff --git a/src/extractors/taglibextractor.cpp b/src/extractors/taglibextractor.cpp
index fbd3bc1d..f97f8ccd 100644
--- a/src/extractors/taglibextractor.cpp
+++ b/src/extractors/taglibextractor.cpp
@@ -288,21 +288,23 @@ void extractId3Tags(TagLib::ID3v2::Tag* Id3Tags, ExtractionResult* result)
      */
     lstID3v2 = Id3Tags->frameListMap()["POPM"];
     if (!lstID3v2.isEmpty()) {
-        TagLib::ID3v2::PopularimeterFrame *ratingFrame = static_cast<TagLib::ID3v2::PopularimeterFrame *>(lstID3v2.front());
-        int rating = ratingFrame->rating();
-        if (rating == 0) {
-            rating = 0;
-        } else if (rating == 1) {
-            TagLib::String ratingProvider = ratingFrame->email();
-            if (ratingProvider == "no@email" || ratingProvider == "org.kde.kfilemetadata") {
-                rating = 1;
-            } else {
-                rating = 2;
+        TagLib::ID3v2::PopularimeterFrame *ratingFrame = dynamic_cast<TagLib::ID3v2::PopularimeterFrame *>(lstID3v2.front());
+        if (ratingFrame) {
+            int rating = ratingFrame->rating();
+            if (rating == 0) {
+                rating = 0;
+            } else if (rating == 1) {
+                TagLib::String ratingProvider = ratingFrame->email();
+                if (ratingProvider == "no@email" || ratingProvider == "org.kde.kfilemetadata") {
+                    rating = 1;
+                } else {
+                    rating = 2;
+                }
+            } else if (rating >= 1 && rating <= 255) {
+                rating = static_cast<int>(0.032 * rating + 2);
             }
-        } else if (rating >= 1 && rating <= 255) {
-            rating = static_cast<int>(0.032 * rating + 2);
+            result->add(Property::Rating, rating);
         }
-        result->add(Property::Rating, rating);
     }
 }
 
@@ -371,11 +373,13 @@ extractId3Cover(const TagLib::ID3v2::Tag* Id3Tags,
 
     using PictureFrame = TagLib::ID3v2::AttachedPictureFrame;
     for (const auto& frame : std::as_const(lstID3v2)) {
-        const auto *coverFrame = static_cast<PictureFrame *>(frame);
-        const auto imageType = mapTaglibType<PictureFrame::Type>(coverFrame->type());
-        if (types & imageType) {
-            const auto& picture = coverFrame->picture();
-            images.insert(imageType, QByteArray(picture.data(), picture.size()));
+        const auto *coverFrame = dynamic_cast<PictureFrame *>(frame);
+        if (coverFrame) {
+            const auto imageType = mapTaglibType<PictureFrame::Type>(coverFrame->type());
+            if (types & imageType) {
+                const auto& picture = coverFrame->picture();
+                images.insert(imageType, QByteArray(picture.data(), picture.size()));
+            }
         }
     }
     return images;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.