diff options
Diffstat (limited to 'lib/libexif/ExifParse.cpp')
-rw-r--r-- | lib/libexif/ExifParse.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/libexif/ExifParse.cpp b/lib/libexif/ExifParse.cpp index 4f39a51b51..635d82f600 100644 --- a/lib/libexif/ExifParse.cpp +++ b/lib/libexif/ExifParse.cpp @@ -451,11 +451,32 @@ void CExifParse::ProcessDir(const unsigned char* const DirStart, case TAG_USERCOMMENT: { - const int EXIF_COMMENT_HDR_LENGTH = 8; // All comment tags have 8 bytes of header info - int length = max(ByteCount - EXIF_COMMENT_HDR_LENGTH, 0); - length = min(length, MAX_COMMENT); - strncpy(m_ExifInfo->Comments, (char *)ValuePtr+EXIF_COMMENT_HDR_LENGTH, length); -// FixComment(comment); // Ensure comment is printable + // The UserComment allows comments without the charset limitations of ImageDescription. + // Therefore the UserComment field is prefixed by a CharacterCode field (8 Byte): + // - ASCII: 'ASCII\0\0\0' + // - Unicode: 'UNICODE\0' + // - JIS X208-1990: 'JIS\0\0\0\0\0' + // - Unknown: '\0\0\0\0\0\0\0\0' (application specific) + + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_UNKNOWN; + + const int EXIF_COMMENT_CHARSET_LENGTH = 8; + if (ByteCount >= EXIF_COMMENT_CHARSET_LENGTH) + { + // As some implementations use spaces instead of \0 for the padding, + // we're not so strict and check only the prefix. + if (memcmp(ValuePtr, "ASCII", 5) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_ASCII; + else if (memcmp(ValuePtr, "UNICODE", 7) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_UNICODE; + else if (memcmp(ValuePtr, "JIS", 3) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_JIS; + + int length = ByteCount - EXIF_COMMENT_CHARSET_LENGTH; + length = min(length, MAX_COMMENT); + memcpy(m_ExifInfo->Comments, ValuePtr + EXIF_COMMENT_CHARSET_LENGTH, length); +// FixComment(comment); // Ensure comment is printable + } } break; |