/src/exif_loader_fuzzer.cc
Line  | Count  | Source  | 
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  |  |  | 
20  | 73.2k  | void content_func(ExifEntry *entry, void *user_data) { | 
21  | 73.2k  |   char buf[10000];  | 
22  | 73.2k  |   exif_entry_get_value(entry, buf, sizeof(buf));  | 
23  | 73.2k  | }  | 
24  |  |  | 
25  | 55.6k  | void data_func(ExifContent *content, void *user_data) { | 
26  | 55.6k  |   exif_content_foreach_entry(content, content_func, NULL);  | 
27  | 55.6k  | }  | 
28  |  |  | 
29  |  | static void  | 
30  | 11.1k  | test_exif_data (ExifData *d) { | 
31  | 11.1k  |   unsigned int i, c;  | 
32  | 11.1k  |   char v[1024], *p;  | 
33  | 11.1k  |   ExifMnoteData *md;  | 
34  |  |  | 
35  | 11.1k  |   md = exif_data_get_mnote_data (d);  | 
36  | 11.1k  |   if (!md) { | 
37  | 3.85k  |     return;  | 
38  | 3.85k  |   }  | 
39  |  |  | 
40  | 7.27k  |   exif_mnote_data_ref (md);  | 
41  | 7.27k  |   exif_mnote_data_unref (md);  | 
42  |  |  | 
43  | 7.27k  |   c = exif_mnote_data_count (md);  | 
44  | 1.68M  |   for (i = 0; i < c; i++) { | 
45  | 1.67M  |     const char *name = exif_mnote_data_get_name (md, i);  | 
46  | 1.67M  |     if (!name) { | 
47  | 1.98k  |       break;  | 
48  | 1.98k  |     }  | 
49  | 1.67M  |     exif_mnote_data_get_title (md, i);  | 
50  | 1.67M  |     exif_mnote_data_get_description (md, i);  | 
51  | 1.67M  |     exif_mnote_data_get_value (md, i, v, sizeof (v));  | 
52  | 1.67M  |   }  | 
53  | 7.27k  | }  | 
54  |  |  | 
55  |  |  | 
56  | 11.4k  | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 
57  | 11.4k  |   ExifLoader *loader = exif_loader_new();  | 
58  | 11.4k  |   ExifData *exif_data;  | 
59  | 11.4k  |   if (!loader) { | 
60  | 0  |     return 0;  | 
61  | 0  |   }  | 
62  | 11.4k  |   exif_loader_write(loader, const_cast<unsigned char*>(data), size);  | 
63  | 11.4k  |   exif_data = exif_loader_get_data(loader);  | 
64  | 11.4k  |   if(!exif_data) { | 
65  | 368  |     exif_loader_unref(loader);  | 
66  | 368  |     return 0;  | 
67  | 368  |   }  | 
68  | 11.1k  |   exif_data_foreach_content(exif_data, data_func, NULL);  | 
69  | 11.1k  |   test_exif_data (exif_data);  | 
70  | 11.1k  |   exif_loader_unref(loader);  | 
71  | 11.1k  |   exif_data_unref(exif_data);  | 
72  | 11.1k  |   return 0;  | 
73  | 11.4k  | }  |