summaryrefslogtreecommitdiff
path: root/ext/exif
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2003-01-18 18:32:19 +0000
committerIlia Alshanetsky <iliaa@php.net>2003-01-18 18:32:19 +0000
commite0654de5905737e4bf5e7c94dc59403da9b7394f (patch)
tree489357304320736c43b1337b40fc6b69eefaad96 /ext/exif
parent21b449995336d7030fcfcefc4545a9ddc248f5e6 (diff)
downloadphp-git-e0654de5905737e4bf5e7c94dc59403da9b7394f.tar.gz
Removed the no longer needed memory allocation checks.
Diffstat (limited to 'ext/exif')
-rw-r--r--ext/exif/exif.c175
1 files changed, 22 insertions, 153 deletions
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index 7cbaac6f07..882b916315 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -234,17 +234,13 @@ static size_t php_strnlen(char* str, size_t maxlen) {
/* {{{ 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
@@ -1332,10 +1328,6 @@ static char *exif_get_sectionlist(int sectionlist TSRMLS_DC)
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++) {
@@ -1468,9 +1460,6 @@ static int exif_file_sections_add(image_info_type *ImageInfo, int type, size_t s
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;
@@ -1479,9 +1468,7 @@ static int exif_file_sections_add(image_info_type *ImageInfo, int type, size_t s
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;
@@ -1497,14 +1484,10 @@ static int exif_file_sections_realloc(image_info_type *ImageInfo, int section_in
{
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;
@@ -1541,10 +1524,6 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
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];
@@ -1552,10 +1531,6 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
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) {
@@ -1572,11 +1547,6 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
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:
@@ -1604,10 +1574,6 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
info_data->length = 0;
info_value->s = estrdup("");
}
- if (!info_value->s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
break;
case TAG_FMT_USHORT:
@@ -1623,10 +1589,6 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
} 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;
}
@@ -1699,10 +1661,6 @@ static void exif_iif_add_int(image_info_type *image_info, int section_index, cha
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];
@@ -1710,10 +1668,6 @@ static void exif_iif_add_int(image_info_type *image_info, int section_index, cha
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++;
@@ -1730,28 +1684,16 @@ static void exif_iif_add_str(image_info_type *image_info, int section_index, cha
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++;
@@ -1787,20 +1729,12 @@ static void exif_iif_add_buffer(image_info_type *image_info, int section_index,
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));
@@ -1809,10 +1743,6 @@ static void exif_iif_add_buffer(image_info_type *image_info, int section_index,
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;
}
@@ -2308,10 +2238,6 @@ static void* exif_ifd_make_value(image_info_data *info_data, int motorola_intel
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;
@@ -2418,13 +2344,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo TSRMLS_DC) {
}
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;
@@ -2453,13 +2372,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo TSRMLS_DC) {
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 {
@@ -2507,9 +2419,6 @@ static void exif_thumbnail_extract(image_info_type *ImageInfo, char *offset, siz
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);
}
/* }}} */
@@ -2524,10 +2433,6 @@ static int exif_process_undefined(char **result, char *value, size_t byte_count
*/
if (byte_count) {
(*result) = estrndup(value, byte_count); /* NULL @ byte_count!!! */
- if (!*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
return byte_count+1;
}
return 0;
@@ -2568,10 +2473,6 @@ static int exif_process_string(char **result, char *value, size_t byte_count TSR
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;
}
/* }}} */
@@ -2813,10 +2714,6 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
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 {
/*
@@ -2903,11 +2800,8 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
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 */
@@ -2927,14 +2821,10 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
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:
@@ -3267,10 +3157,7 @@ static int exif_scan_JPEG_header(image_info_type *ImageInfo TSRMLS_DC)
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. */
@@ -3293,10 +3180,7 @@ static int exif_scan_JPEG_header(image_info_type *ImageInfo TSRMLS_DC)
/* 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) {
@@ -3461,10 +3345,7 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
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
@@ -3618,16 +3499,12 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
#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);
}
}
}
@@ -3655,16 +3532,12 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
#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");
@@ -3857,10 +3730,6 @@ PHP_FUNCTION(exif_read_data)
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;