Coverage Report

Created: 2025-06-16 06:41

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