Coverage Report

Created: 2025-07-18 06:34

/src/exif_from_data_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 <libexif/exif-data.h>
16
#include <libexif/exif-loader.h>
17
#include <stddef.h>
18
#include <stdlib.h>
19
20
/* Extract all MakerNote tags */
21
10.3k
static void mnote_dump(ExifData *data) {
22
10.3k
    ExifMnoteData *mn = exif_data_get_mnote_data(data);
23
10.3k
    if (mn) {
24
7.09k
        int num = exif_mnote_data_count(mn);
25
26
        /* Loop through all MakerNote tags */
27
21.4M
        for (int i=0; i < num; ++i) {
28
21.4M
            char buf[1024];
29
21.4M
            exif_mnote_data_get_value(mn, i, buf, sizeof(buf));
30
21.4M
        }
31
7.09k
    }
32
10.3k
}
33
34
71.6k
static void dump_value(ExifEntry *entry, void *user_data) {
35
71.6k
  char buf[1024];
36
71.6k
  exif_entry_get_value(entry, buf, sizeof(buf));
37
71.6k
}
38
39
51.8k
static void data_func(ExifContent *content, void *user_data) {
40
51.8k
  exif_content_foreach_entry(content, dump_value, NULL);
41
51.8k
}
42
43
/* This is like exif_data_dump but without writing to stdout */
44
10.3k
static void data_dump(ExifData *data) {
45
10.3k
  exif_data_foreach_content(data, data_func, NULL);
46
10.3k
}
47
48
10.3k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
49
50
  // Parse tags using (ultimately) exif_data_load_data()
51
10.3k
  auto image = exif_data_new_from_data(data, size);
52
10.3k
  if (image) {
53
    // Exercise the EXIF tag manipulation code
54
10.3k
    exif_data_get_mnote_data(image);
55
10.3k
    data_dump(image);
56
10.3k
    mnote_dump(image);
57
10.3k
    unsigned char *buf;
58
10.3k
    unsigned int sz;
59
10.3k
    exif_data_save_data(image, &buf, &sz);
60
10.3k
    free(buf);
61
10.3k
    exif_data_fix(image);
62
10.3k
    exif_data_unref(image);
63
10.3k
  }
64
65
10.3k
  return 0;
66
10.3k
}