EXIF library (libexif) Internals 0.6.26
test-fuzzer.c
Go to the documentation of this file.
1
27#include <string.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <sys/stat.h>
31
32#include "libexif/exif-data.h"
33#include "libexif/exif-loader.h"
34#include "libexif/exif-system.h"
35
36#undef USE_LOG
37
38#ifdef USE_LOG
39static void
40logfunc(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args, void *data)
41{
42 fprintf( stderr, "test-fuzzer: code=%d domain=%s ", code, domain);
43 vfprintf (stderr, format, args);
44 fprintf (stderr, "\n");
45}
46#endif
47
49void content_foreach_func(ExifEntry *entry, void *callback_data);
50void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
51{
52 char buf[2001];
53
54 /* ensure \0 */
55 buf[sizeof(buf)-1] = 0;
56 buf[sizeof(buf)-2] = 0;
57 exif_tag_get_name(entry->tag);
59 exif_entry_get_value(entry, buf, sizeof(buf)-1);
60 if (buf[sizeof(buf)-2] != 0) abort();
61}
62
63
65void data_foreach_func(ExifContent *content, void *callback_data);
66void data_foreach_func(ExifContent *content, void *callback_data)
67{
68 printf(" Content %p: ifd=%d\n", (void *)content, exif_content_get_ifd(content));
69 exif_content_foreach_entry(content, content_foreach_func, callback_data);
70}
71static int
73{
74 unsigned int i, c;
75 char v[1024];
76 ExifMnoteData *md;
77
78 fprintf (stdout, "Byte order: %s\n",
80
82 if (!md) {
83 fprintf (stderr, "Could not parse maker note!\n");
84 return 1;
85 }
86
89
90 c = exif_mnote_data_count (md);
91 for (i = 0; i < c; i++) {
92 const char *name = exif_mnote_data_get_name (md, i);
93 if (!name) continue;
97 exif_mnote_data_get_value (md, i, v, sizeof (v));
98 }
99
100 return 0;
101}
102
103
104
106static void test_parse(const char *filename, void *callback_data)
107{
108 ExifData *d;
109 ExifLoader *loader = exif_loader_new();
110 unsigned int buf_size;
111 unsigned char *buf;
112 FILE *f;
113 struct stat stbuf;
114#ifdef USE_LOG
115 ExifLog *log = exif_log_new ();
116
117 exif_log_set_func(log, logfunc, NULL);
118#endif
119
120 /* try the exif loader */
121 d = exif_data_new_from_file(filename);
122#ifdef USE_LOG
123 exif_data_log (d, log);
124#endif
126 test_exif_data (d);
127
128 buf = NULL;
129 exif_data_save_data (d, &buf, &buf_size);
130 free (buf);
131
133
134 buf = NULL;
135 exif_data_save_data (d, &buf, &buf_size);
136 free (buf);
137
139
140 /* try the exif data writer ... different than the loader */
141 if (-1 == stat(filename,&stbuf))
142 perror("stat");
143 f = fopen(filename,"r");
144 if (!f) {
145 fprintf(stderr, "Error opening %s\n", filename);
146 return;
147 }
148
149 buf = malloc(stbuf.st_size);
150 if (fread (buf, stbuf.st_size, 1, f) != 1) {
151 fprintf(stderr, "Error reading %s\n", filename);
152 return;
153 }
154 fclose(f);
155
156 exif_loader_write(loader, buf, stbuf.st_size);
157 free (buf);
158
159 d = exif_loader_get_data(loader);
161 test_exif_data (d);
162 exif_loader_unref(loader);
164}
165
166
168int main(const int argc, const char *argv[])
169{
170 int i;
171 void *callback_data = NULL;
172 for (i=1; i<argc; i++) {
173 test_parse(argv[i], callback_data);
174 }
175 return 0;
176}
const char * exif_byte_order_get_name(ExifByteOrder order)
Return a short, localized, textual name for the given byte order.
@ EXIF_BYTE_ORDER_INTEL
Little-endian byte order.
ExifIfd exif_content_get_ifd(ExifContent *c)
Return the IFD number in which the given ExifContent is found.
void exif_content_foreach_entry(ExifContent *content, ExifContentForeachEntryFunc func, void *data)
Executes function on each EXIF tag in this IFD in turn.
void exif_data_set_byte_order(ExifData *data, ExifByteOrder order)
Set the byte order to use for this EXIF data.
Definition exif-data.c:1229
void exif_data_unref(ExifData *data)
Definition exif-data.c:1110
ExifByteOrder exif_data_get_byte_order(ExifData *data)
Return the byte order in use by this EXIF structure.
Definition exif-data.c:1185
ExifMnoteData * exif_data_get_mnote_data(ExifData *d)
Return the MakerNote data out of the EXIF data.
Definition exif-data.c:92
ExifData * exif_data_new_from_file(const char *path)
Allocate a new ExifData and load EXIF data from a JPEG file.
Definition exif-data.c:1087
void exif_data_save_data(ExifData *data, unsigned char **d, unsigned int *ds)
Store raw EXIF data representing the ExifData structure into a memory buffer.
Definition exif-data.c:1042
void exif_data_foreach_content(ExifData *data, ExifDataForeachContentFunc func, void *user_data)
Execute a function on each IFD in turn.
Definition exif-data.c:1194
void exif_data_log(ExifData *data, ExifLog *log)
Set the log message object for all IFDs.
Definition exif-data.c:1245
Defines the ExifData type and the associated functions.
const char * exif_entry_get_value(ExifEntry *e, char *val, unsigned int maxlen)
Return a localized textual representation of the value of the EXIF entry.
Definition exif-entry.c:854
const char * exif_format_get_name(ExifFormat format)
Return a textual representation of the given EXIF data type.
Definition exif-format.c:55
ExifFormat format
Definition exif-format.c:35
ExifLoader * exif_loader_new(void)
Allocate a new ExifLoader.
ExifData * exif_loader_get_data(ExifLoader *loader)
Create an ExifData from the data in the loader.
void exif_loader_unref(ExifLoader *loader)
Decrease the refcount of the ExifLoader.
unsigned char exif_loader_write(ExifLoader *eld, unsigned char *buf, unsigned int len)
Load a buffer into the ExifLoader from a memory buffer.
Defines the ExifLoader type.
ExifLog * exif_log_new(void)
Create a new logging instance.
Definition exif-log.c:88
ExifLogCode code
Definition exif-log.c:41
void exif_log_set_func(ExifLog *log, ExifLogFunc func, void *data)
Register log callback function.
Definition exif-log.c:125
ExifLogCode
Definition exif-log.h:56
char * exif_mnote_data_get_value(ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen)
Return a textual representation of the value of the MakerNote entry.
void exif_mnote_data_ref(ExifMnoteData *d)
const char * exif_mnote_data_get_description(ExifMnoteData *d, unsigned int n)
Returns verbose textual description of the given MakerNote tag.
const char * exif_mnote_data_get_title(ExifMnoteData *d, unsigned int n)
Returns textual title of the given MakerNote tag.
const char * exif_mnote_data_get_name(ExifMnoteData *d, unsigned int n)
Returns textual name of the given MakerNote tag.
unsigned int exif_mnote_data_count(ExifMnoteData *d)
Return the number of tags in the MakerNote.
void exif_mnote_data_unref(ExifMnoteData *d)
System specific definitions, not for installation!
#define UNUSED(param)
Definition exif-system.h:31
const char * exif_tag_get_name(ExifTag tag)
Definition exif-tag.c:1151
const char * name
int main(void)
Represents the entire EXIF data found in an image.
Definition exif-data.h:48
Data found in one EXIF tag.
Definition exif-entry.h:45
ExifFormat format
Type of data in this entry.
Definition exif-entry.h:50
ExifTag tag
EXIF tag for this entry.
Definition exif-entry.h:47
void data_foreach_func(ExifContent *content, void *callback_data)
Definition test-fuzzer.c:66
static int test_exif_data(ExifData *d)
Definition test-fuzzer.c:72
static void test_parse(const char *filename, void *callback_data)
void content_foreach_func(ExifEntry *entry, void *callback_data)
Completely parse all files given on the command line.

libexif Generated by doxygen