Skip to content

Commit 6f48ccf

Browse files
natwyattnikic
authored andcommitted
Fix compilation errors when EXIF_DEBUG is defined
Fix warnings and error when compiling with EXIF_DEBUG defined. Closes GH-5838.
1 parent 99c7896 commit 6f48ccf

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

ext/exif/exif.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,10 @@ static char *exif_get_tagname_key(int tag_num, char *buf, size_t buf_size, tag_t
13741374
/* {{{ exif_char_dump
13751375
* Do not use! This is a debug function... */
13761376
#ifdef EXIF_DEBUG
1377-
static unsigned char* exif_char_dump(unsigned char * addr, int len, int offset)
1377+
static char* exif_char_dump(char * addr, int len, int offset)
13781378
{
1379-
static unsigned char buf[4096+1];
1380-
static unsigned char tmp[20];
1379+
static char buf[4096+1];
1380+
static char tmp[20];
13811381
int c, i, p=0, n = 5+31;
13821382

13831383
p += slprintf(buf+p, sizeof(buf)-p, "\nDump Len: %08X (%d)", len, len);
@@ -1387,7 +1387,7 @@ static unsigned char* exif_char_dump(unsigned char * addr, int len, int offset)
13871387
p += slprintf(buf+p, sizeof(buf)-p, "\n%08X: ", i+offset);
13881388
}
13891389
if (i<len) {
1390-
c = *addr++;
1390+
c = *((unsigned char *)addr++);
13911391
p += slprintf(buf+p, sizeof(buf)-p, "%02X ", c);
13921392
tmp[i%16] = c>=32 ? c : '.';
13931393
tmp[(i%16)+1] = '\0';
@@ -1536,7 +1536,7 @@ static double php_ifd_get_double(char *data) {
15361536
}
15371537

15381538
#ifdef EXIF_DEBUG
1539-
char * exif_dump_data(int *dump_free, int format, int components, int length, int motorola_intel, char *value_ptr) /* {{{ */
1539+
char * exif_dump_data(int *dump_free, int format, int components, int motorola_intel, char *value_ptr) /* {{{ */
15401540
{
15411541
char *dump;
15421542
int len;
@@ -1556,7 +1556,7 @@ char * exif_dump_data(int *dump_free, int format, int components, int length, in
15561556
}
15571557
*dump_free = 1;
15581558
if (components > 1) {
1559-
len = spprintf(&dump, 0, "(%d,%d) {", components, length);
1559+
len = spprintf(&dump, 0, "(%d) {", components);
15601560
} else {
15611561
len = spprintf(&dump, 0, "{");
15621562
}
@@ -1981,7 +1981,12 @@ typedef struct {
19811981
} image_info_type;
19821982
/* }}} */
19831983

1984+
// EXIF_DEBUG can produce lots of messages
1985+
#ifndef EXIF_DEBUG
19841986
#define EXIF_MAX_ERRORS 10
1987+
#else
1988+
#define EXIF_MAX_ERRORS 100000
1989+
#endif
19851990

19861991
/* {{{ exif_error_docref */
19871992
static void exif_error_docref(const char *docref EXIFERR_DC, image_info_type *ImageInfo, int type, const char *format, ...)
@@ -2003,7 +2008,7 @@ static void exif_error_docref(const char *docref EXIFERR_DC, image_info_type *Im
20032008
{
20042009
char *buf;
20052010

2006-
spprintf(&buf, 0, "%s(%d): %s", _file, _line, format);
2011+
spprintf(&buf, 0, "%s(%ld): %s", _file, _line, format);
20072012
php_verror(docref, ImageInfo && ImageInfo->FileName ? ImageInfo->FileName:"", type, buf, args);
20082013
efree(buf);
20092014
}
@@ -2080,6 +2085,11 @@ static inline zend_bool exif_offset_info_contains(
20802085
return start >= info->valid_start && end <= info->valid_end;
20812086
}
20822087

2088+
static inline int exif_offset_info_length(const exif_offset_info *info)
2089+
{
2090+
return info->valid_end - info->valid_start;
2091+
}
2092+
20832093
/* {{{ exif_file_sections_add
20842094
Add a file_section to image_info
20852095
returns the used block or -1. if size>0 and data == NULL buffer of size is allocated
@@ -2444,9 +2454,6 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im
24442454

24452455
for (int i = 0; i<image_info->info_list[section_index].count; i++) {
24462456
image_info_data *info_data = &image_info->info_list[section_index].list[i];
2447-
#ifdef EXIF_DEBUG
2448-
int info_tag = info_data->tag; /* conversion */
2449-
#endif
24502457
image_info_value *info_value = &info_data->value;
24512458
const char *name = info_data->name;
24522459
if (!name) {
@@ -2846,9 +2853,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo) {
28462853
int i, byte_count;
28472854
image_info_list *info_list;
28482855
image_info_data *info_data;
2849-
#ifdef EXIF_DEBUG
2850-
char tagname[64];
2851-
#endif
28522856

28532857
if (!ImageInfo->read_thumbnail || !ImageInfo->Thumbnail.offset || !ImageInfo->Thumbnail.size) {
28542858
return; /* ignore this call */
@@ -3134,7 +3138,7 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
31343138
for (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) {
31353139
if (i==sizeof(maker_note_array)/sizeof(maker_note_type)) {
31363140
#ifdef EXIF_DEBUG
3137-
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "No maker note data found. Detected maker: %s (length = %d)", ImageInfo->make, strlen(ImageInfo->make));
3141+
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);
31383142
#endif
31393143
/* unknown manufacturer, not an error, use it as a string */
31403144
return true;
@@ -3152,14 +3156,13 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
31523156

31533157
if (value_len < 2 || maker_note->offset >= value_len - 1) {
31543158
/* Do not go past the value end */
3155-
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "IFD data too short: 0x%04X offset 0x%04X", value_len, maker_note->offset);
31563159
return true;
31573160
}
31583161

31593162
dir_start = value_ptr + maker_note->offset;
31603163

31613164
#ifdef EXIF_DEBUG
3162-
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s @x%04X + 0x%04X=%d: %s", exif_get_sectionname(section_index), (int)dir_start-(int)offset_base+maker_note->offset+displacement, value_len, value_len, exif_char_dump(value_ptr, value_len, (int)dir_start-(int)offset_base+maker_note->offset+displacement));
3165+
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s @x%04X + 0x%04X=%d: %s", exif_get_sectionname(section_index), (intptr_t)dir_start-(intptr_t)info->offset_base+maker_note->offset+displacement, value_len, value_len, exif_char_dump(value_ptr, value_len, (intptr_t)dir_start-(intptr_t)info->offset_base+maker_note->offset+displacement));
31633166
#endif
31643167

31653168
ImageInfo->sections_found |= FOUND_MAKERNOTE;
@@ -3315,8 +3318,10 @@ static bool exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, co
33153318

33163319
ImageInfo->sections_found |= FOUND_ANY_TAG;
33173320
#ifdef EXIF_DEBUG
3318-
dump_data = exif_dump_data(&dump_free, format, components, length, ImageInfo->motorola_intel, value_ptr);
3319-
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process tag(x%04X=%s,@x%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);
3321+
dump_data = exif_dump_data(&dump_free, format, components, ImageInfo->motorola_intel, value_ptr);
3322+
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE,
3323+
"Process tag(x%04X=%s,@x%04X + x%04X(=%d)): %s%s %s",
3324+
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);
33203325
if (dump_free) {
33213326
efree(dump_data);
33223327
}
@@ -3561,7 +3566,7 @@ static bool exif_process_IFD_in_JPEG(image_info_type *ImageInfo, char *dir_start
35613566
int NextDirOffset = 0;
35623567

35633568
#ifdef EXIF_DEBUG
3564-
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s (x%04X(=%d))", exif_get_sectionname(section_index), IFDlength, IFDlength);
3569+
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s (x%04X(=%d))", exif_get_sectionname(section_index), exif_offset_info_length(info), exif_offset_info_length(info));
35653570
#endif
35663571

35673572
ImageInfo->sections_found |= FOUND_IFD0;

0 commit comments

Comments
 (0)