Coverage Report

Created: 2025-08-29 06:06

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