--- embedaddon/php/ext/exif/exif.c 2012/02/21 23:47:54 1.1.1.1 +++ embedaddon/php/ext/exif/exif.c 2013/07/22 01:31:40 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exif.c,v 1.1.1.1 2012/02/21 23:47:54 misho Exp $ */ +/* $Id: exif.c,v 1.1.1.3 2013/07/22 01:31:40 misho Exp $ */ /* ToDos * @@ -76,16 +76,6 @@ #include "ext/standard/php_image.h" #include "ext/standard/info.h" -#if defined(PHP_WIN32) || (HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)) -#define EXIF_USE_MBSTRING 1 -#else -#define EXIF_USE_MBSTRING 0 -#endif - -#if EXIF_USE_MBSTRING -#include "ext/mbstring/mbstring.h" -#endif - /* needed for ssize_t definition */ #include @@ -148,7 +138,7 @@ const zend_function_entry exif_functions[] = { }; /* }}} */ -#define EXIF_VERSION "1.4 $Id: exif.c,v 1.1.1.1 2012/02/21 23:47:54 misho Exp $" +#define EXIF_VERSION "1.4 $Id: exif.c,v 1.1.1.3 2013/07/22 01:31:40 misho Exp $" /* {{{ PHP_MINFO_FUNCTION */ @@ -186,23 +176,31 @@ ZEND_DECLARE_MODULE_GLOBALS(exif) ZEND_INI_MH(OnUpdateEncode) { -#if EXIF_USE_MBSTRING - if (new_value && strlen(new_value) && !php_mb_check_encoding_list(new_value TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value); - return FAILURE; + if (new_value && new_value_length) { + const zend_encoding **return_list; + size_t return_size; + if (FAILURE == zend_multibyte_parse_encoding_list(new_value, new_value_length, + &return_list, &return_size, 0 TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value); + return FAILURE; + } + efree(return_list); } -#endif return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } ZEND_INI_MH(OnUpdateDecode) { -#if EXIF_USE_MBSTRING - if (!php_mb_check_encoding_list(new_value TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value); - return FAILURE; + if (new_value) { + const zend_encoding **return_list; + size_t return_size; + if (FAILURE == zend_multibyte_parse_encoding_list(new_value, new_value_length, + &return_list, &return_size, 0 TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value); + return FAILURE; + } + efree(return_list); } -#endif return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } @@ -234,7 +232,11 @@ static PHP_GINIT_FUNCTION(exif) PHP_MINIT_FUNCTION(exif) { REGISTER_INI_ENTRIES(); - REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", EXIF_USE_MBSTRING, CONST_CS | CONST_PERSISTENT); + if (zend_hash_exists(&module_registry, "mbstring", sizeof("mbstring"))) { + REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", 1, CONST_CS | CONST_PERSISTENT); + } else { + REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", 0, CONST_CS | CONST_PERSISTENT); + } return SUCCESS; } /* }}} */ @@ -251,9 +253,7 @@ PHP_MSHUTDOWN_FUNCTION(exif) /* {{{ exif dependencies */ static const zend_module_dep exif_module_deps[] = { ZEND_MOD_REQUIRED("standard") -#if EXIF_USE_MBSTRING - ZEND_MOD_REQUIRED("mbstring") -#endif + ZEND_MOD_OPTIONAL("mbstring") ZEND_MOD_END }; /* }}} */ @@ -1697,11 +1697,7 @@ static void exif_iif_add_value(image_info_type *image_ case TAG_FMT_STRING: if (value) { length = php_strnlen(value, length); - if (PG(magic_quotes_runtime)) { - info_value->s = php_addslashes(value, length, &length, 0 TSRMLS_CC); - } else { - info_value->s = estrndup(value, length); - } + info_value->s = estrndup(value, length); info_data->length = length; } else { info_data->length = 0; @@ -1724,11 +1720,7 @@ static void exif_iif_add_value(image_info_type *image_ case TAG_FMT_UNDEFINED: if (value) { /* do not recompute length here */ - if (PG(magic_quotes_runtime)) { - info_value->s = php_addslashes(value, length, &length, 0 TSRMLS_CC); - } else { - info_value->s = estrndup(value, length); - } + info_value->s = estrndup(value, length); info_data->length = length; } else { info_data->length = 0; @@ -1850,11 +1842,7 @@ static void exif_iif_add_str(image_info_type *image_in info_data->format = TAG_FMT_STRING; info_data->length = 1; info_data->name = estrdup(name); - if (PG(magic_quotes_runtime)) { - info_data->value.s = php_addslashes(value, strlen(value), NULL, 0 TSRMLS_CC); - } else { - info_data->value.s = estrdup(value); - } + info_data->value.s = estrdup(value); image_info->sections_found |= 1<info_list[section_index].count++; } @@ -1895,17 +1883,9 @@ static void exif_iif_add_buffer(image_info_type *image info_data->format = TAG_FMT_UNDEFINED; info_data->length = length; info_data->name = estrdup(name); - if (PG(magic_quotes_runtime)) { -#ifdef EXIF_DEBUG - exif_error_docref(NULL EXIFERR_CC, image_info, E_NOTICE, "Adding %s as buffer%s", name, exif_char_dump(value, length, 0)); -#endif - info_data->value.s = php_addslashes(value, length, &length, 0 TSRMLS_CC); - info_data->length = length; - } else { - info_data->value.s = safe_emalloc(length, 1, 1); - memcpy(info_data->value.s, value, length); - info_data->value.s[length] = 0; - } + info_data->value.s = safe_emalloc(length, 1, 1); + memcpy(info_data->value.s, value, length); + info_data->value.s[length] = 0; image_info->sections_found |= 1<info_list[section_index].count++; } @@ -2598,7 +2578,6 @@ static int exif_process_undefined(char **result, char /* {{{ exif_process_string_raw * Copy a string in Exif header to a character string returns length of allocated buffer if any. */ -#if !EXIF_USE_MBSTRING static int exif_process_string_raw(char **result, char *value, size_t byte_count) { /* we cannot use strlcpy - here the problem is that we have to copy NUL * chars up to byte_count, we also have to add a single NUL character to @@ -2612,7 +2591,6 @@ static int exif_process_string_raw(char **result, char } return 0; } -#endif /* }}} */ /* {{{ exif_process_string @@ -2639,11 +2617,8 @@ static int exif_process_string(char **result, char *va static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount TSRMLS_DC) { int a; - -#if EXIF_USE_MBSTRING char *decode; size_t len;; -#endif *pszEncoding = NULL; /* Copy the comment */ @@ -2652,7 +2627,6 @@ static int exif_process_user_comment(image_info_type * *pszEncoding = estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; -#if EXIF_USE_MBSTRING /* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16) * since we have no encoding support for the BOM yet we skip that. */ @@ -2669,34 +2643,38 @@ static int exif_process_user_comment(image_info_type * } else { decode = ImageInfo->decode_unicode_le; } - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, decode, &len TSRMLS_CC); + if (zend_multibyte_encoding_converter( + (unsigned char**)pszInfoPtr, + &len, + (unsigned char*)szValuePtr, + ByteCount, + zend_multibyte_fetch_encoding(ImageInfo->encode_unicode TSRMLS_CC), + zend_multibyte_fetch_encoding(decode TSRMLS_CC) + TSRMLS_CC) < 0) { + len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); + } return len; -#else - return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); -#endif - } else - if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) { + } else if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) { *pszEncoding = estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; - } else - if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) { + } else if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) { /* JIS should be tanslated to MB or we leave it to the user - leave it to the user */ *pszEncoding = estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; -#if EXIF_USE_MBSTRING - if (ImageInfo->motorola_intel) { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_be, &len TSRMLS_CC); - } else { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_le, &len TSRMLS_CC); + if (zend_multibyte_encoding_converter( + (unsigned char**)pszInfoPtr, + &len, + (unsigned char*)szValuePtr, + ByteCount, + zend_multibyte_fetch_encoding(ImageInfo->encode_jis TSRMLS_CC), + zend_multibyte_fetch_encoding(ImageInfo->motorola_intel ? ImageInfo->decode_jis_be : ImageInfo->decode_jis_le TSRMLS_CC) + TSRMLS_CC) < 0) { + len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); } return len; -#else - return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); -#endif - } else - if (!memcmp(szValuePtr, "\0\0\0\0\0\0\0\0", 8)) { + } else if (!memcmp(szValuePtr, "\0\0\0\0\0\0\0\0", 8)) { /* 8 NULL means undefined and should be ASCII... */ *pszEncoding = estrdup("UNDEFINED"); szValuePtr = szValuePtr+8; @@ -2724,19 +2702,17 @@ static int exif_process_unicode(image_info_type *Image xp_field->tag = tag; /* Copy the comment */ -#if EXIF_USE_MBSTRING -/* What if MS supports big-endian with XP? */ -/* if (ImageInfo->motorola_intel) { - xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &xp_field->size TSRMLS_CC); - } else { - xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC); - }*/ - xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC); + if (zend_multibyte_encoding_converter( + (unsigned char**)&xp_field->value, + &xp_field->size, + (unsigned char*)szValuePtr, + ByteCount, + zend_multibyte_fetch_encoding(ImageInfo->encode_unicode TSRMLS_CC), + zend_multibyte_fetch_encoding(ImageInfo->motorola_intel ? ImageInfo->decode_unicode_be : ImageInfo->decode_unicode_le TSRMLS_CC) + TSRMLS_CC) < 0) { + xp_field->size = exif_process_string_raw(&xp_field->value, szValuePtr, ByteCount); + } return xp_field->size; -#else - xp_field->size = exif_process_string_raw(&xp_field->value, szValuePtr, ByteCount); - return xp_field->size; -#endif } /* }}} */ @@ -3278,7 +3254,7 @@ static void exif_process_APP12(image_info_type *ImageI if ((l1 = php_strnlen(buffer+2, length-2)) > 0) { exif_iif_add_tag(ImageInfo, SECTION_APP12, "Company", TAG_NONE, TAG_FMT_STRING, l1, buffer+2 TSRMLS_CC); if (length > 2+l1+1) { - l2 = php_strnlen(buffer+2+l1+1, length-2-l1+1); + l2 = php_strnlen(buffer+2+l1+1, length-2-l1-1); exif_iif_add_tag(ImageInfo, SECTION_APP12, "Info", TAG_NONE, TAG_FMT_STRING, l2, buffer+2+l1+1 TSRMLS_CC); } } @@ -3428,6 +3404,10 @@ static int exif_scan_JPEG_header(image_info_type *Imag case M_SOF13: case M_SOF14: case M_SOF15: + if ((itemlen - 2) < 6) { + return FALSE; + } + exif_process_SOFn(Data, marker, &sof_info); ImageInfo->Width = sof_info.width; ImageInfo->Height = sof_info.height; @@ -3880,7 +3860,7 @@ static int exif_read_file(image_info_type *ImageInfo, ImageInfo->motorola_intel = -1; /* flag as unknown */ - ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); + ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", STREAM_MUST_SEEK|IGNORE_PATH, NULL); if (!ImageInfo->infile) { exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Unable to open file"); return FALSE; @@ -3942,7 +3922,7 @@ PHP_FUNCTION(exif_read_data) image_info_type ImageInfo; char tmp[64], *sections_str, *s; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sbb", &p_name, &p_name_len, &p_sections_needed, &p_sections_needed_len, &sub_arrays, &read_thumbnail) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|sbb", &p_name, &p_name_len, &p_sections_needed, &p_sections_needed_len, &sub_arrays, &read_thumbnail) == FAILURE) { return; } @@ -4123,7 +4103,7 @@ PHP_FUNCTION(exif_thumbnail) WRONG_PARAM_COUNT; } - if (zend_parse_parameters(arg_c TSRMLS_CC, "s|z/z/z/", &p_name, &p_name_len, &p_width, &p_height, &p_imagetype) == FAILURE) { + if (zend_parse_parameters(arg_c TSRMLS_CC, "p|z/z/z/", &p_name, &p_name_len, &p_width, &p_height, &p_imagetype) == FAILURE) { return; } @@ -4185,7 +4165,7 @@ PHP_FUNCTION(exif_imagetype) return; } - stream = php_stream_open_wrapper(imagefile, "rb", IGNORE_PATH|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(imagefile, "rb", IGNORE_PATH|REPORT_ERRORS, NULL); if (stream == NULL) { RETURN_FALSE;