/* {{{ error messages
*/
-static const char * EXIF_ERROR_EALLOC = "Cannot allocate memory for all data";
static const char * EXIF_ERROR_FILEEOF = "Unexpected end of file reached";
static const char * EXIF_ERROR_CORRUPT = "File structure corrupted";
static const char * EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of file reached";
-static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined file section";
-#define EXIF_ERRLOG_EALLOC php_error_docref(NULL TSRMLS_CC, E_ERROR, EXIF_ERROR_EALLOC);
#define EXIF_ERRLOG_FILEEOF php_error_docref(NULL TSRMLS_CC, E_WARNING, EXIF_ERROR_FILEEOF);
#define EXIF_ERRLOG_CORRUPT php_error_docref(NULL TSRMLS_CC, E_WARNING, EXIF_ERROR_CORRUPT);
#define EXIF_ERRLOG_THUMBEOF php_error_docref(NULL TSRMLS_CC, E_WARNING, EXIF_ERROR_THUMBEOF);
-#define EXIF_ERRLOG_FSREALLOC php_error_docref(NULL TSRMLS_CC, E_WARNING, EXIF_ERROR_FSREALLOC);
/* }}} */
/* {{{ format description defines
len += strlen(exif_get_sectionname(i))+2;
}
sections = emalloc(len+1);
- if (!sections) {
- EXIF_ERRLOG_EALLOC
- return NULL;
- }
sections[0] = '\0';
len = 0;
for(i=0; i<SECTION_COUNT; i++) {
int count = ImageInfo->file.count;
tmp = erealloc(ImageInfo->file.list, (count+1)*sizeof(file_section));
- if (tmp == NULL) {
- return 0;
- }
ImageInfo->file.list = tmp;
ImageInfo->file.list[count].type = 0xFFFF;
ImageInfo->file.list[count].data = NULL;
if (!size) {
data = NULL;
} else if (data == NULL) {
- if ((data = emalloc(size)) == NULL) {
- return -1;
- }
+ data = emalloc(size);
}
ImageInfo->file.list[count].type = type;
ImageInfo->file.list[count].data = data;
{
void *tmp;
- if (section_index >= ImageInfo->file.count) {
- EXIF_ERRLOG_FSREALLOC
- return -1;
- }
- if (!(tmp = erealloc(ImageInfo->file.list[section_index].data, size)) && size) {
- EXIF_ERRLOG_EALLOC
+ if (size <= 0 || section_index >= ImageInfo->file.count) {
return -1;
}
+ tmp = erealloc(ImageInfo->file.list[section_index].data, size);
ImageInfo->file.list[section_index].data = tmp;
ImageInfo->file.list[section_index].size = size;
return 0;
image_info_data *list;
list = erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->format = format;
info_data->length = length;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
info_value = &info_data->value;
switch (format) {
info_data->length = 0;
info_value->s = estrdup("");
}
- if (!info_value->s) {
- EXIF_ERRLOG_EALLOC
- info_data->length = 0;
- break; /* better return with "" instead of possible causing problems */
- }
break;
default:
info_data->length = 0;
info_value->s = estrdup("");
}
- if (!info_value->s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
break;
case TAG_FMT_USHORT:
} else
if (length>1) {
info_data->value.list = emalloc(length*sizeof(image_info_value));
- if (!info_data->value.list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
} else {
info_value = &info_data->value;
}
image_info_data *list;
list = erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->format = TAG_FMT_SLONG;
info_data->length = 1;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
info_data->value.i = value;
image_info->sections_found |= 1<<section_index;
image_info->info_list[section_index].count++;
if (value) {
list = erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->tag = TAG_NONE;
info_data->format = TAG_FMT_STRING;
info_data->length = 1;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
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);
- if (!info_data->value.s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
}
image_info->sections_found |= 1<<section_index;
image_info->info_list[section_index].count++;
if (value) {
list = erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->tag = TAG_NONE;
info_data->format = TAG_FMT_UNDEFINED;
info_data->length = length;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
if (PG(magic_quotes_runtime)) {
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, image_info, E_NOTICE, "Adding %s as buffer%s", name, exif_char_dump(value, length, 0));
info_data->length = length;
} else {
info_data->value.s = emalloc(length+1);
- if (!info_data->value.s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
memcpy(info_data->value.s, value, length);
info_data->value.s[length] = 0;
}
byte_count = php_tiff_bytes_per_format[info_data->format] * info_data->length;
value_ptr = emalloc(max(byte_count, 4));
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- return NULL;
- }
memset(value_ptr, 0, 4);
if (!info_data->length) {
return value_ptr;
}
new_move = new_size;
new_data = erealloc(ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size+new_size);
- if (!new_data) {
- EXIF_ERRLOG_EALLOC
- efree(ImageInfo->Thumbnail.data);
- ImageInfo->Thumbnail.data = NULL;
- ImageInfo->Thumbnail.size = 0;
- return;
- }
ImageInfo->Thumbnail.data = new_data;
memmove(ImageInfo->Thumbnail.data + new_move, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
ImageInfo->Thumbnail.size += new_size;
php_ifd_set16u(new_data + 2, info_data->format, ImageInfo->motorola_intel);
php_ifd_set32u(new_data + 4, info_data->length, ImageInfo->motorola_intel);
value_ptr = exif_ifd_make_value(info_data, ImageInfo->motorola_intel TSRMLS_CC);
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- efree(ImageInfo->Thumbnail.data);
- ImageInfo->Thumbnail.data = NULL;
- ImageInfo->Thumbnail.size = 0;
- return;
- }
if (byte_count <= 4) {
memmove(new_data+8, value_ptr, 4);
} else {
return;
}
ImageInfo->Thumbnail.data = estrndup(offset + ImageInfo->Thumbnail.offset, ImageInfo->Thumbnail.size);
- if (!ImageInfo->Thumbnail.data) {
- EXIF_ERRLOG_EALLOC
- }
exif_thumbnail_build(ImageInfo TSRMLS_CC);
}
/* }}} */
*/
if (byte_count) {
(*result) = estrndup(value, byte_count); /* NULL @ byte_count!!! */
- if (!*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
return byte_count+1;
}
return 0;
return exif_process_undefined(result, value, byte_count TSRMLS_CC);
}
(*result) = estrndup("", 1); /* force empty string */
- if (!*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
return byte_count+1;
}
/* }}} */
if (byte_count>sizeof(cbuf)) {
/* mark as outside range and get buffer */
value_ptr = emalloc(byte_count);
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
outside = value_ptr;
} else {
/*
ImageInfo->CopyrightPhotographer = estrdup(value_ptr);
ImageInfo->CopyrightEditor = estrdup(value_ptr+length+1);
ImageInfo->Copyright = emalloc(strlen(value_ptr)+strlen(value_ptr+length+1)+3);
- if (!ImageInfo->Copyright) {
- EXIF_ERRLOG_EALLOC
- } else {
- sprintf(ImageInfo->Copyright, "%s, %s", value_ptr, value_ptr+length+1);
- }
+
+ sprintf(ImageInfo->Copyright, "%s, %s", value_ptr, value_ptr+length+1);
/* format = TAG_FMT_UNDEFINED; this musn't be ASCII */
/* but we are not supposed to change this */
/* keep in mind that image_info does not store editor value */
case TAG_XP_KEYWORDS:
case TAG_XP_SUBJECT:
tmp_xp = (xp_field_type*)erealloc(ImageInfo->xp_fields.list, sizeof(xp_field_type)*(ImageInfo->xp_fields.count+1));
- if (!tmp_xp) {
- EXIF_ERRLOG_EALLOC
- } else {
- 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 TSRMLS_CC);
- }
+ 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 TSRMLS_CC);
break;
case TAG_FNUMBER:
return FALSE;
}
- if ((sn=exif_file_sections_add(ImageInfo, marker, itemlen+1, NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo, marker, itemlen+1, NULL);
Data = ImageInfo->file.list[sn].data;
/* Store first two pre-read bytes. */
/* Determine how much file is left. */
fpos = php_stream_tell(ImageInfo->infile);
size = ImageInfo->FileSize - fpos;
- if ((sn=exif_file_sections_add(ImageInfo, M_PSEUDO, size, NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo, M_PSEUDO, size, NULL);
Data = ImageInfo->file.list[sn].data;
got = php_stream_read(ImageInfo->infile, Data, size);
if (got != size) {
tag_table_type tag_table = exif_get_tag_table(section_index);
if (ImageInfo->FileSize >= dir_offset+2) {
- if ((sn=exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, ImageInfo, E_NOTICE, "read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, 2);
#endif
#endif
if (!ImageInfo->Thumbnail.data) {
ImageInfo->Thumbnail.data = emalloc(ImageInfo->Thumbnail.size);
- if (!ImageInfo->Thumbnail.data) {
- EXIF_ERRLOG_EALLOC
- } else {
- php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
- fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
- if (fgot < ImageInfo->Thumbnail.size) {
- EXIF_ERRLOG_THUMBEOF
- }
- exif_thumbnail_build(ImageInfo TSRMLS_CC);
+ php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
+ fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
+ if (fgot < ImageInfo->Thumbnail.size) {
+ EXIF_ERRLOG_THUMBEOF
}
+ exif_thumbnail_build(ImageInfo TSRMLS_CC);
}
}
}
#endif
if (!ImageInfo->Thumbnail.data && ImageInfo->Thumbnail.offset && ImageInfo->Thumbnail.size && ImageInfo->read_thumbnail) {
ImageInfo->Thumbnail.data = emalloc(ImageInfo->Thumbnail.size);
- if (!ImageInfo->Thumbnail.data) {
- EXIF_ERRLOG_EALLOC
- } else {
- php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
- fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
- if (fgot < ImageInfo->Thumbnail.size) {
- EXIF_ERRLOG_THUMBEOF
- }
- exif_thumbnail_build(ImageInfo TSRMLS_CC);
+ php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
+ fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
+ if (fgot < ImageInfo->Thumbnail.size) {
+ EXIF_ERRLOG_THUMBEOF
}
+ exif_thumbnail_build(ImageInfo TSRMLS_CC);
}
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, ImageInfo, E_NOTICE, "read next IFD (THUMBNAIL) done");
if(ac >= 2) {
convert_to_string_ex(p_sections_needed);
sections_str = emalloc(strlen(Z_STRVAL_PP(p_sections_needed))+3);
- if (!sections_str) {
- EXIF_ERRLOG_EALLOC
- RETURN_FALSE;
- }
sprintf(sections_str, ",%s,", Z_STRVAL_PP(p_sections_needed));
/* sections_str DOES start with , and SPACES are NOT allowed in names */
s = sections_str;