Bug#573166: libkexiv2-7: libkexiv2 doesn't extract language alternative value correctly
Package: libkexiv2-7
Version: 4:4.3.4-1
Severity: normal
Tags: patch
The KExiv2::getXmpTagStringLangAlt() fails to extract a language
alternative value, no matter what the specified language alternative
is. A detailed description how I came across this problem is described
@ https://bugs.kde.org/show_bug.cgi?id=199317 - a result of using
kipi-plugins.
Please, consider the attached patch for the Debian package until it is
accepted/reworked upstream.
The patch itself has a header describing all the implementation
details.
Thank you,
Jan Capek
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.30-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=cs_CZ.UTF-8, LC_CTYPE=cs_CZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libkexiv2-7 depends on:
ii kdelibs5 4:4.3.4-3 core libraries for all KDE 4 appli
ii libc6 2.10.2-2 GNU C Library: Shared libraries
ii libexiv2-6 0.19-1 EXIF/IPTC metadata manipulation li
ii libgcc1 1:4.4.2-9 GCC support library
ii libqtcore4 4:4.5.3-4 Qt 4 core module
ii libqtgui4 4:4.5.3-4 Qt 4 GUI module
ii libstdc++6 4.4.2-9 The GNU Standard C++ Library v3
libkexiv2-7 recommends no packages.
libkexiv2-7 suggests no packages.
-- no debconf information
Language alternative accessor fix (KExiv2::getXmpTagStringLangAlt())
- removed broken code that was using toString(long index) method of
the iterator to extract a particular language alternative
value. This maybe a bug in libexiv2, however, there is no need for
handwritten parsing of the value via detectLanguageAlt() since
libexiv2 provides all the necessary functionality for this - see the
next point
- the proposed mechanism iterates through all language alternatives
stored in an Exiv2::LangAltValue instance and selects only the
requested one
- NOTE: the implementation of KExiv2::getXmpTagStringLangAlt() may
also use getXmpTagStringListLangAlt() to extract the list of
language alternatives into a hash map and then extract only the
relevant item from it. This would be slightly slower but a much
nicer code ;-).
Index: kdegraphics-4.3.4/libs/libkexiv2/libkexiv2/kexiv2xmp.cpp
===================================================================
--- kdegraphics-4.3.4.orig/libs/libkexiv2/libkexiv2/kexiv2xmp.cpp
+++ kdegraphics-4.3.4/libs/libkexiv2/libkexiv2/kexiv2xmp.cpp
@@ -420,19 +420,22 @@ QString KExiv2::getXmpTagStringLangAlt(c
{
Exiv2::XmpData xmpData(d->xmpMetadata);
Exiv2::XmpKey key(xmpTagName);
- for (Exiv2::XmpData::iterator it = xmpData.begin(); it != xmpData.end(); ++it)
+ /* TODO: we should consider using getXmpTagStringListLangAlt() method and extract only the
+ * requested language alternative. This would allow eliminating all this code but would
+ * become more memory intensive. In reality, how many language alternatives users have..? */
+ for (Exiv2::XmpData::const_iterator it = xmpData.begin(); it != xmpData.end(); ++it)
{
if (it->key() == xmpTagName && it->typeId() == Exiv2::langAlt)
{
- for (int i = 0; i < it->count(); i++)
- {
- std::ostringstream os;
- os << it->toString(i);
- QString lang;
- QString tagValue = QString::fromUtf8(os.str().c_str());
- tagValue = detectLanguageAlt(tagValue, lang);
+ const Exiv2::LangAltValue &lav = dynamic_cast<const Exiv2::LangAltValue&>(it->value());
+ for(std::map<std::string, std::string>::const_iterator lit = lav.value_.begin();
+ lit != lav.value_.end(); ++lit) {
+ QString lang = QString::fromUtf8(lit->first.c_str());
+ QString tagValue = QString::fromUtf8(lit->second.c_str());
if (langAlt == lang)
{
+ kDebug(51003) << "Extracting XMP tag='" << xmpTagName << "' lang='" << lang << "' value='"
+ << tagValue << "'" << endl;
if (escapeCR)
tagValue.replace("\n", " ");
Reply to: