diff options
-rw-r--r-- | ext/exif/exif.c | 19 | ||||
-rw-r--r-- | ext/exif/tests/exif003.phpt | 9 |
2 files changed, 22 insertions, 6 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); diff --git a/ext/exif/tests/exif003.phpt b/ext/exif/tests/exif003.phpt index 310fdf5f5b..d61864e909 100644 --- a/ext/exif/tests/exif003.phpt +++ b/ext/exif/tests/exif003.phpt @@ -1,10 +1,13 @@ --TEST-- Check for exif_read_data, Unicode user comment --SKIPIF-- -<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?> +<?php + if (!extension_loaded('exif')) die('skip exif extension not available'); + if (!extension_loaded('mbstring')) die('skip mbstring extension not available'); +?> --INI-- -output_handler = -zlib.output_compression = Off +output_handler= +zlib.output_compression=0 exif.decode_unicode_motorola=UCS-2BE exif.encode_unicode=ISO-8859-15 --FILE-- |