From b11ea43ee53b89939a317b81d60ffe130add6ca8 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 15 Feb 2023 00:04:10 +0800 Subject: [PATCH] fix: crash if unusual xmp tag used when open property dlg --- app/exiv2wrapper.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/exiv2wrapper.cpp b/app/exiv2wrapper.cpp index 324285a..36d280d 100644 --- a/app/exiv2wrapper.cpp +++ b/app/exiv2wrapper.cpp @@ -35,14 +35,20 @@ void Exiv2Wrapper::cacheSection(Collection collection) for (; it != end; ++it) { QString key = QString::fromUtf8(it->key().c_str()); if (it->tagName().substr(0, 2) == "0x") continue; - QString label = QString::fromLocal8Bit(it->tagLabel().c_str()); - std::ostringstream stream; - stream << *it; - QString value = QString::fromUtf8(stream.str().c_str()); - m_metadataValue.insert(key, value); - m_metadataLabel.insert(key, label); - - qDebug() << key << label << value; + // We might get exceptions like "No namespace info available for XMP prefix `Item'" + // when trying to get tagLabel() data from a Xmpdatum if the tag is not common-used. + // We don't care for those rare tags so let's just use a try-cache... + try { + QString label = QString::fromLocal8Bit(it->tagLabel().c_str()); + std::ostringstream stream; + stream << *it; + QString value = QString::fromUtf8(stream.str().c_str()); + m_metadataValue.insert(key, value); + m_metadataLabel.insert(key, label); + qDebug() << key << label << value; + } catch (Exiv2::BasicError & err) { + qWarning() << "Error loading key" << key << ":" << err.code() << err.what(); + } } }