Coverage Report

Created: 2025-07-11 06:13

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