diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 859324b1b96f5..0f63c76e2323f 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -1833,7 +1833,7 @@ typedef struct { #define FOUND_WINXP (1<= and <= to do the checks, respectively. */ - end = start + length; + const char *end = start + length; return start >= info->valid_start && end <= info->valid_end; } @@ -2157,18 +2156,15 @@ static int exif_file_sections_realloc(image_info_type *ImageInfo, int section_in /* {{{ exif_file_section_free Discard all file_sections in ImageInfo */ -static bool exif_file_sections_free(image_info_type *ImageInfo) +static void exif_file_sections_free(image_info_type *ImageInfo) { - int i; - if (ImageInfo->file.count) { - for (i=0; ifile.count; i++) { + for (int i = 0; ifile.count; i++) { EFREE_IF(ImageInfo->file.list[i].data); } } EFREE_IF(ImageInfo->file.list); ImageInfo->file.count = 0; - return true; } /* }}} */ @@ -2185,7 +2181,7 @@ static image_info_data *exif_alloc_image_info_data(image_info_list *info_list) { /* {{{ exif_iif_add_value Add a value to image_info */ -static void exif_iif_add_value(image_info_type *image_info, int section_index, char *name, int tag, int format, size_t length, void* value, size_t value_len, int motorola_intel) +static void exif_iif_add_value(image_info_type *image_info, int section_index, const char *name, int tag, int format, size_t length, void* value, size_t value_len, int motorola_intel) { size_t idex; void *vptr, *vptr_end; @@ -2324,7 +2320,7 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c /* {{{ exif_iif_add_tag Add a tag from IFD to image_info */ -static void exif_iif_add_tag(image_info_type *image_info, int section_index, char *name, int tag, int format, size_t length, void* value, size_t value_len) +static void exif_iif_add_tag(image_info_type *image_info, int section_index, const char *name, int tag, int format, size_t length, void* value, size_t value_len) { exif_iif_add_value(image_info, section_index, name, tag, format, length, value, value_len, image_info->motorola_intel); } @@ -2333,7 +2329,7 @@ static void exif_iif_add_tag(image_info_type *image_info, int section_index, cha /* {{{ exif_iif_add_int Add an int value to image_info */ -static void exif_iif_add_int(image_info_type *image_info, int section_index, char *name, int value) +static void exif_iif_add_int(image_info_type *image_info, int section_index, const char *name, int value) { image_info_data *info_data = exif_alloc_image_info_data(&image_info->info_list[section_index]); info_data->tag = TAG_NONE; @@ -2348,7 +2344,7 @@ static void exif_iif_add_int(image_info_type *image_info, int section_index, cha /* {{{ exif_iif_add_str Add a string value to image_info MUST BE NUL TERMINATED */ -static void exif_iif_add_str(image_info_type *image_info, int section_index, char *name, char *value) +static void exif_iif_add_str(image_info_type *image_info, int section_index, const char *name, const char *value) { if (value) { image_info_data *info_data = @@ -2366,7 +2362,7 @@ static void exif_iif_add_str(image_info_type *image_info, int section_index, cha /* {{{ exif_iif_add_fmt Add a format string value to image_info MUST BE NUL TERMINATED */ -static void exif_iif_add_fmt(image_info_type *image_info, int section_index, char *name, char *value, ...) +static void exif_iif_add_fmt(image_info_type *image_info, int section_index, const char *name, char *value, ...) { char *tmp; va_list arglist; @@ -2384,7 +2380,7 @@ static void exif_iif_add_fmt(image_info_type *image_info, int section_index, cha /* {{{ exif_iif_add_str Add a string value to image_info MUST BE NUL TERMINATED */ -static void exif_iif_add_buffer(image_info_type *image_info, int section_index, char *name, int length, char *value) +static void exif_iif_add_buffer(image_info_type *image_info, int section_index, const char *name, int length, const char *value) { if (value) { image_info_data *info_data = @@ -2405,11 +2401,10 @@ static void exif_iif_add_buffer(image_info_type *image_info, int section_index, Free memory allocated for image_info */ static void exif_iif_free(image_info_type *image_info, int section_index) { - int i; void *f; /* faster */ if (image_info->info_list[section_index].count) { - for (i=0; i < image_info->info_list[section_index].count; i++) { + for (int i = 0; i < image_info->info_list[section_index].count; i++) { if ((f=image_info->info_list[section_index].list[i].name) != NULL) { efree(f); } @@ -2450,7 +2445,6 @@ static void exif_iif_free(image_info_type *image_info, int section_index) { * Add image_info to associative array value. */ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *image_info, int section_index) { - char buffer[64], uname[64]; int idx = 0, unknown = 0; if (!image_info->info_list[section_index].count) { @@ -2468,6 +2462,8 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im image_info_data *info_data = &image_info->info_list[section_index].list[i]; image_info_value *info_value = &info_data->value; const char *name = info_data->name; + char uname[64]; + if (!name) { snprintf(uname, sizeof(uname), "%d", unknown++); name = uname; @@ -2518,6 +2514,7 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im array_init(&array); } for (int ap = 0; ap < l; ap++) { + char buffer[64]; if (l>1) { info_value = &info_data->value.list[ap]; } @@ -2787,8 +2784,7 @@ PHP_FUNCTION(exif_tagname) * Create a value for an ifd from an info_data pointer */ static void* exif_ifd_make_value(image_info_data *info_data, int motorola_intel) { size_t byte_count; - char *value_ptr, *data_ptr; - size_t i; + char *value_ptr; image_info_value *info_value; @@ -2810,8 +2806,8 @@ static void* exif_ifd_make_value(image_info_data *info_data, int motorola_intel) *value_ptr = info_data->value.i; return value_ptr; } else { - data_ptr = value_ptr; - for(i=0; ilength; i++) { + char *data_ptr = value_ptr; + for(size_t i = 0; i < info_data->length; i++) { if (info_data->length==1) { info_value = &info_data->value; } else { @@ -2980,7 +2976,7 @@ static void exif_thumbnail_extract(image_info_type *ImageInfo, const exif_offset /* {{{ exif_process_undefined * Copy a string/buffer in Exif header to a character string and return length of allocated buffer if any. */ -static int exif_process_undefined(char **result, char *value, size_t byte_count) { +static int exif_process_undefined(char **result, const 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 * force end of string. @@ -2996,7 +2992,7 @@ static int exif_process_undefined(char **result, char *value, size_t byte_count) /* {{{ exif_process_string_raw * Copy a string in Exif header to a character string returns length of allocated buffer if any. */ -static int exif_process_string_raw(char **result, char *value, size_t byte_count) { +static int exif_process_string_raw(char **result, const 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 * force end of string. @@ -3014,7 +3010,7 @@ static int exif_process_string_raw(char **result, char *value, size_t byte_count /* {{{ exif_process_string * Copy a string in Exif header to a character string and return length of allocated buffer if any. * In contrast to exif_process_string this function does always return a string buffer */ -static int exif_process_string(char **result, char *value, size_t byte_count) { +static int exif_process_string(char **result, const char *value, size_t byte_count) { /* we cannot use strlcpy - here the problem is that we cannot use strlen to * determine length of string and we cannot use strlcpy with len=byte_count+1 * because then we might get into an EXCEPTION if we exceed an allocated @@ -3032,10 +3028,8 @@ static int exif_process_string(char **result, char *value, size_t byte_count) { /* {{{ exif_process_user_comment * Process UserComment in IFD. */ -static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount) +static int exif_process_user_comment(const image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount) { - int a; - char *decode; size_t len; *pszEncoding = NULL; @@ -3043,7 +3037,8 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP if (ByteCount>=8) { const zend_encoding *from, *to; if (!memcmp(szValuePtr, "UNICODE\0", 8)) { - *pszEncoding = estrdup((const char*)szValuePtr); + char *decode; + *pszEncoding = estrdup(szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; /* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16) @@ -3076,12 +3071,12 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP } return len; } else if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) { - *pszEncoding = estrdup((const char*)szValuePtr); + *pszEncoding = estrdup(szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; } else if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) { /* JIS should be translated to MB or we leave it to the user - leave it to the user */ - *pszEncoding = estrdup((const char*)szValuePtr); + *pszEncoding = estrdup(szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; /* XXX this will fail again if encoding_converter returns on error something different than SIZE_MAX */ @@ -3107,7 +3102,7 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP /* Olympus has this padded with trailing spaces. Remove these first. */ if (ByteCount>0) { - for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) { + for (int a = ByteCount-1; a && szValuePtr[a]==' '; a--) { (szValuePtr)[a] = '\0'; } } @@ -3120,7 +3115,7 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP /* {{{ exif_process_unicode * Process unicode field in IFD. */ -static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_field, int tag, char *szValuePtr, int ByteCount) +static int exif_process_unicode(const image_info_type *ImageInfo, xp_field_type *xp_field, int tag, const char *szValuePtr, int ByteCount) { xp_field->tag = tag; xp_field->value = NULL; @@ -3128,7 +3123,7 @@ static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_fi if (zend_multibyte_encoding_converter( (unsigned char**)&xp_field->value, &xp_field->size, - (unsigned char*)szValuePtr, + (const unsigned char*)szValuePtr, ByteCount, zend_multibyte_fetch_encoding(ImageInfo->encode_unicode), zend_multibyte_fetch_encoding(ImageInfo->motorola_intel ? ImageInfo->decode_unicode_be : ImageInfo->decode_unicode_le) @@ -3143,14 +3138,13 @@ static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_fi * Process nested IFDs directories in Maker Note. */ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * value_ptr, int value_len, const exif_offset_info *info, size_t displacement) { - size_t i; - int de, section_index = SECTION_MAKERNOTE; + int section_index = SECTION_MAKERNOTE; int NumDirEntries, old_motorola_intel; const maker_note_type *maker_note; char *dir_start; exif_offset_info new_info; - for (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) { + for (size_t i = 0; i <= sizeof(maker_note_array)/sizeof(maker_note_type); i++) { if (i==sizeof(maker_note_array)/sizeof(maker_note_type)) { #ifdef EXIF_DEBUG exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "No maker note data found. Detected maker: %s (length = %d)", ImageInfo->make, ImageInfo->make ? strlen(ImageInfo->make) : 0); @@ -3231,7 +3225,7 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val break; } - for (de=0;detag_table)) { @@ -3259,16 +3253,10 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val * Process one of the nested IFDs directories. */ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entry, const exif_offset_info *info, size_t displacement, int section_index, int ReadNextIFD, tag_table_type tag_table) { - size_t length; unsigned int tag, format, components; char *value_ptr, tagname[64], cbuf[32], *outside=NULL; - size_t byte_count, offset_val, fpos, fgot; + size_t byte_count, offset_val; int64_t byte_count_signed; - xp_field_type *tmp_xp; -#ifdef EXIF_DEBUG - char *dump_data; - int dump_free; -#endif /* EXIF_DEBUG */ tag = php_ifd_get16u(dir_entry, ImageInfo->motorola_intel); format = php_ifd_get16u(dir_entry+2, ImageInfo->motorola_intel); @@ -3316,9 +3304,9 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr value_ptr = cbuf; } - fpos = php_stream_tell(ImageInfo->infile); + size_t fpos = php_stream_tell(ImageInfo->infile); php_stream_seek(ImageInfo->infile, displacement+offset_val, SEEK_SET); - fgot = php_stream_tell(ImageInfo->infile); + size_t fgot = php_stream_tell(ImageInfo->infile); if (fgot!=displacement+offset_val) { EFREE_IF(outside); exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Wrong file pointer: 0x%08X != 0x%08X", fgot, displacement+offset_val); @@ -3341,7 +3329,8 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr ImageInfo->sections_found |= FOUND_ANY_TAG; #ifdef EXIF_DEBUG - dump_data = exif_dump_data(&dump_free, format, components, ImageInfo->motorola_intel, value_ptr); + int dump_free; + char *dump_data = exif_dump_data(&dump_free, format, components, ImageInfo->motorola_intel, value_ptr); exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process tag(x%04X=%s,@0x%04X + x%04X(=%d)): %s%s %s", tag, exif_get_tagname_debug(tag, tag_table), offset_val+displacement, byte_count, byte_count, (components>1)&&format!=TAG_FMT_UNDEFINED&&format!=TAG_FMT_STRING?"ARRAY OF ":"", exif_get_tagformat(format), dump_data); @@ -3394,7 +3383,8 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr } else { if (section_index==SECTION_IFD0 || section_index==SECTION_EXIF) switch(tag) { - case TAG_COPYRIGHT: + case TAG_COPYRIGHT: { + size_t length; /* check for " NUL NUL" */ if (byte_count>1 && (length=zend_strnlen(value_ptr, byte_count)) > 0) { if (lengthUserComment); @@ -3427,13 +3418,14 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr case TAG_XP_COMMENTS: case TAG_XP_AUTHOR: case TAG_XP_KEYWORDS: - case TAG_XP_SUBJECT: - tmp_xp = (xp_field_type*)safe_erealloc(ImageInfo->xp_fields.list, (ImageInfo->xp_fields.count+1), sizeof(xp_field_type), 0); + case TAG_XP_SUBJECT: { + xp_field_type *tmp_xp = (xp_field_type*)safe_erealloc(ImageInfo->xp_fields.list, (ImageInfo->xp_fields.count+1), sizeof(xp_field_type), 0); ImageInfo->sections_found |= FOUND_WINXP; ImageInfo->xp_fields.list = tmp_xp; ImageInfo->xp_fields.count++; exif_process_unicode(ImageInfo, &(ImageInfo->xp_fields.list[ImageInfo->xp_fields.count-1]), tag, value_ptr, byte_count); break; + } case TAG_FNUMBER: /* Simplest way of expressing aperture, so I trust it the most. @@ -4034,7 +4026,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir { int i, sn, num_entries, sub_section_index = 0; unsigned char *dir_entry; - size_t ifd_size, dir_size, entry_offset, next_offset, entry_length, entry_value=0, fgot; + size_t ifd_size, dir_size, next_offset, entry_length, entry_value=0; int entry_tag , entry_type; tag_table_type tag_table = exif_get_tag_table(section_index); @@ -4121,7 +4113,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir break; } } else { - entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel); + size_t entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel); /* if entry needs expanding ifd cache and entry is at end of current ifd cache. */ /* otherwise there may be huge holes between two entries */ if (entry_offset + entry_length > dir_offset + ifd_size @@ -4180,7 +4172,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir sub_section_index = SECTION_THUMBNAIL; break; } - entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel); + size_t entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel); #ifdef EXIF_DEBUG exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Next IFD: %s @0x%04X", exif_get_sectionname(sub_section_index), entry_offset); #endif @@ -4197,7 +4189,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir if (!ImageInfo->Thumbnail.data) { ImageInfo->Thumbnail.data = safe_emalloc(ImageInfo->Thumbnail.size, 1, 0); php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET); - fgot = exif_read_from_stream_file_looped(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size); + size_t fgot = exif_read_from_stream_file_looped(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size); if (fgot != ImageInfo->Thumbnail.size) { EXIF_ERRLOG_THUMBEOF(ImageInfo) efree(ImageInfo->Thumbnail.data); @@ -4237,7 +4229,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir if (!ImageInfo->Thumbnail.data && ImageInfo->Thumbnail.offset && ImageInfo->Thumbnail.size && ImageInfo->read_thumbnail) { ImageInfo->Thumbnail.data = safe_emalloc(ImageInfo->Thumbnail.size, 1, 0); php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET); - fgot = exif_read_from_stream_file_looped(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size); + size_t fgot = exif_read_from_stream_file_looped(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size); if (fgot != ImageInfo->Thumbnail.size) { EXIF_ERRLOG_THUMBEOF(ImageInfo) efree(ImageInfo->Thumbnail.data); @@ -4286,70 +4278,79 @@ static bool exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offs static bool exif_scan_FILE_header(image_info_type *ImageInfo) { unsigned char file_header[8]; - bool ret = false; ImageInfo->FileType = IMAGE_FILETYPE_UNKNOWN; - if (ImageInfo->FileSize >= 2) { - php_stream_seek(ImageInfo->infile, 0, SEEK_SET); - if (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)file_header, 2) != 2) { + if (UNEXPECTED(ImageInfo->FileSize < 2)) { + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File too small (%d)", ImageInfo->FileSize); + return false; + } + + php_stream_seek(ImageInfo->infile, 0, SEEK_SET); + if (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)file_header, 2) != 2) { + return false; + } + + if ((file_header[0]==0xff) && (file_header[1]==M_SOI)) { + ImageInfo->FileType = IMAGE_FILETYPE_JPEG; + if (exif_scan_JPEG_header(ImageInfo)) { + return true; + } else { + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid JPEG file"); + return false; + } + } else if (ImageInfo->FileSize >= 8) { + if (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)(file_header+2), 6) != 6) { return false; } - if ((file_header[0]==0xff) && (file_header[1]==M_SOI)) { - ImageInfo->FileType = IMAGE_FILETYPE_JPEG; - if (exif_scan_JPEG_header(ImageInfo)) { - ret = true; + + if (!memcmp(file_header, "II\x2A\x00", 4)) { + ImageInfo->FileType = IMAGE_FILETYPE_TIFF_II; + ImageInfo->motorola_intel = 0; +#ifdef EXIF_DEBUG + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/II format"); +#endif + ImageInfo->sections_found |= FOUND_IFD0; + if (exif_process_IFD_in_TIFF( + ImageInfo, + php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel), + SECTION_IFD0 + )) { + return true; } else { - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid JPEG file"); - } - } else if (ImageInfo->FileSize >= 8) { - if (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)(file_header+2), 6) != 6) { + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file"); return false; } - if (!memcmp(file_header, "II\x2A\x00", 4)) { - ImageInfo->FileType = IMAGE_FILETYPE_TIFF_II; - ImageInfo->motorola_intel = 0; -#ifdef EXIF_DEBUG - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/II format"); -#endif - ImageInfo->sections_found |= FOUND_IFD0; - if (exif_process_IFD_in_TIFF(ImageInfo, - php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel), - SECTION_IFD0)) { - ret = true; - } else { - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file"); - } - } else if (!memcmp(file_header, "MM\x00\x2a", 4)) { - ImageInfo->FileType = IMAGE_FILETYPE_TIFF_MM; - ImageInfo->motorola_intel = 1; + } else if (!memcmp(file_header, "MM\x00\x2a", 4)) { + ImageInfo->FileType = IMAGE_FILETYPE_TIFF_MM; + ImageInfo->motorola_intel = 1; #ifdef EXIF_DEBUG - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/MM format"); + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/MM format"); #endif - ImageInfo->sections_found |= FOUND_IFD0; - if (exif_process_IFD_in_TIFF(ImageInfo, - php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel), - SECTION_IFD0)) { - ret = true; - } else { - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file"); - } + ImageInfo->sections_found |= FOUND_IFD0; + if (exif_process_IFD_in_TIFF( + ImageInfo, + php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel), + SECTION_IFD0 + )) { + return true; } else { - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File not supported"); + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file"); return false; } + } else { + exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File not supported"); + return false; } - } else { - exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File too small (%d)", ImageInfo->FileSize); } - return ret; + return false; } /* }}} */ /* {{{ exif_discard_imageinfo Discard data scanned by exif_read_file. */ -static bool exif_discard_imageinfo(image_info_type *ImageInfo) +static void exif_discard_imageinfo(image_info_type *ImageInfo) { int i; @@ -4377,7 +4378,6 @@ static bool exif_discard_imageinfo(image_info_type *ImageInfo) } exif_file_sections_free(ImageInfo); memset(ImageInfo, 0, sizeof(*ImageInfo)); - return true; } /* }}} */ @@ -4465,7 +4465,7 @@ static bool exif_read_from_stream(image_info_type *ImageInfo, php_stream *stream /* }}} */ /* {{{ exif_read_from_file */ -static bool exif_read_from_file(image_info_type *ImageInfo, char *FileName, int read_thumbnail, int read_all) +static bool exif_read_from_file(image_info_type *ImageInfo, const char *FileName, int read_thumbnail, int read_all) { bool ret; php_stream *stream; @@ -4497,7 +4497,7 @@ PHP_FUNCTION(exif_read_data) bool ret; int i, sections_needed = 0; image_info_type ImageInfo; - char tmp[64], *sections_str, *s; + char *sections_str; /* Parse arguments */ ZEND_PARSE_PARAMETERS_START(1, 4) @@ -4513,7 +4513,7 @@ PHP_FUNCTION(exif_read_data) if (z_sections_needed) { spprintf(§ions_str, 0, ",%s,", ZSTR_VAL(z_sections_needed)); /* sections_str DOES start with , and SPACES are NOT allowed in names */ - s = sections_str; + char *s = sections_str; while (*++s) { if (*s == ' ') { *s = ','; @@ -4521,6 +4521,7 @@ PHP_FUNCTION(exif_read_data) } for (i = 0; i < SECTION_COUNT; i++) { + char tmp[64]; snprintf(tmp, sizeof(tmp), ",%s,", exif_get_sectionname(i)); if (strstr(sections_str, tmp)) { sections_needed |= 1<