diff options
Diffstat (limited to 'ext/exif/exif.c')
-rw-r--r-- | ext/exif/exif.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 136d069b30..fbefedb91b 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -2549,6 +2549,7 @@ static int exif_process_string(char **result, char *value, size_t byte_count TSR static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount TSRMLS_DC) { int a; + char *decode; #ifdef HAVE_MBSTRING size_t len;; @@ -2562,11 +2563,23 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP szValuePtr = szValuePtr+8; ByteCount -= 8; #ifdef HAVE_MBSTRING - if (ImageInfo->motorola_intel) { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &len TSRMLS_CC); + /* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16) + * since we have no encoding support for the BOM yet we skip that. + */ + if (!memcmp(szValuePtr, "\xFE\xFF", 2)) { + decode = "UCS-2BE"; + szValuePtr = szValuePtr+2; + ByteCount -= 2; + } else if (!memcmp(szValuePtr, "\xFF\xFE", 2)) { + decode = "UCS-2LE"; + szValuePtr = szValuePtr+2; + ByteCount -= 2; + } else if (ImageInfo->motorola_intel) { + decode = ImageInfo->decode_unicode_be; } else { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &len TSRMLS_CC); + decode = ImageInfo->decode_unicode_le; } + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, decode, &len TSRMLS_CC); return len; #else return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); |