From cb74a20421d6d73203b23e02b36fbc08c60bceba Mon Sep 17 00:00:00 2001 From: Sertonix Norson Date: Wed, 30 Sep 2026 17:47:16 +0200 Subject: [PATCH] EXIF: always use little-endian for UTF-16 In practice UTF-16 (especially from windows) uses little-endian without a BOM. By default Qt uses host endianess which causes TIFF_XPTITLE and TIFF_XPKEYWORDS to not be read correctly. Fixes c21b50d699bd --- src/imageformats/microexif.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/imageformats/microexif.cpp b/src/imageformats/microexif.cpp index 6be98dd..30e5f5e 100644 --- a/src/imageformats/microexif.cpp +++ b/src/imageformats/microexif.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include // TIFF 6 specs @@ -1748,9 +1749,10 @@ void MicroExif::setUtf16String(Tags &tags, quint16 tagId, const QString &s) tags.remove(tagId); return; } - auto s16 = s.toStdU16String(); + + QStringEncoder fromUtf16(QStringEncoder::Utf16LE, QStringEncoder::Flag::Stateless); + QByteArray ba = fromUtf16(s); QList uba; - auto ba = QByteArrayView(reinterpret_cast(s16.data()), s.size() * 2); for(auto&& c : ba) uba.append(quint8(c)); uba.append(quint8('\0')); @@ -1763,7 +1765,6 @@ QString MicroExif::utf16String(const Tags &tags, quint16 tagId) auto ba = tags.value(tagId).value>(); if (ba.isEmpty()) return {}; - auto p16 = reinterpret_cast(ba.data()); - auto sz = std::max(ba.size() / 2 - 1, qsizetype()); - return QString::fromUtf16(p16, sz); + QStringDecoder toUtf16(QStringDecoder::Utf16LE, QStringDecoder::Flag::Stateless); + return toUtf16(QByteArrayView(ba.data(), std::max(ba.size() - 2, qsizetype()))); }