1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <stdio.h>
16 #include <stdint.h>
17 #include <libexif/exif-loader.h>
18
19
content_func(ExifEntry * entry,void * user_data)20 void content_func(ExifEntry *entry, void *user_data) {
21 char buf[10000];
22 exif_entry_get_value(entry, buf, sizeof(buf));
23 }
24
data_func(ExifContent * content,void * user_data)25 void data_func(ExifContent *content, void *user_data) {
26 exif_content_foreach_entry(content, content_func, NULL);
27 }
28
29 static void
test_exif_data(ExifData * d)30 test_exif_data (ExifData *d) {
31 unsigned int i, c;
32 char v[1024], *p;
33 ExifMnoteData *md;
34
35 md = exif_data_get_mnote_data (d);
36 if (!md) {
37 return;
38 }
39
40 exif_mnote_data_ref (md);
41 exif_mnote_data_unref (md);
42
43 c = exif_mnote_data_count (md);
44 for (i = 0; i < c; i++) {
45 const char *name = exif_mnote_data_get_name (md, i);
46 if (!name) {
47 break;
48 }
49 exif_mnote_data_get_title (md, i);
50 exif_mnote_data_get_description (md, i);
51 exif_mnote_data_get_value (md, i, v, sizeof (v));
52 }
53 }
54
55
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
57 ExifLoader *loader = exif_loader_new();
58 ExifData *exif_data;
59 if (!loader) {
60 return 0;
61 }
62 exif_loader_write(loader, const_cast<unsigned char*>(data), size);
63 exif_data = exif_loader_get_data(loader);
64 if(!exif_data) {
65 exif_loader_unref(loader);
66 return 0;
67 }
68 exif_data_foreach_content(exif_data, data_func, NULL);
69 test_exif_data (exif_data);
70 exif_loader_unref(loader);
71 exif_data_unref(exif_data);
72 return 0;
73 }
74