Coverage Report

Created: 2026-07-16 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/exiv2/fuzz/fuzz-read-print-write.cpp
Line
Count
Source
1
#include <exiv2/exiv2.hpp>
2
3
#include <cassert>
4
#include <iomanip>
5
#include <iostream>
6
7
30.3k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
8
  // Invalid files generate a lot of warnings, so switch off logging.
9
30.3k
  Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);
10
11
30.3k
  try {
12
30.3k
    Exiv2::DataBuf data_copy(data, size);
13
30.3k
    Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(data_copy.c_data(), size);
14
30.3k
    assert(image.get() != 0);
15
16
30.3k
    image->readMetadata();
17
14.8M
    for (auto& md : image->exifData()) {
18
14.8M
      if (md.tagName().substr(0, 2) != "0x") {
19
599k
        md.print();
20
599k
        md.print(&image->exifData());
21
599k
      }
22
14.8M
    }
23
30.3k
    for (auto& md : image->iptcData()) {
24
2.93k
      if (md.tagName().substr(0, 2) != "0x") {
25
2.00k
        md.print();
26
2.00k
        md.print(&image->exifData());
27
2.00k
      }
28
2.93k
    }
29
30.3k
    for (auto& md : image->xmpData()) {
30
9.13k
      if (md.tagName().substr(0, 2) != "0x") {
31
9.13k
        md.print();
32
9.13k
        md.print(&image->exifData());
33
9.13k
      }
34
9.13k
    }
35
36
    // Print to a std::ostringstream so that the fuzzer doesn't
37
    // produce lots of garbage on stdout.
38
30.3k
    std::ostringstream buffer;
39
30.3k
    image->printStructure(buffer, Exiv2::kpsNone);
40
30.3k
    image->printStructure(buffer, Exiv2::kpsBasic);
41
30.3k
    image->printStructure(buffer, Exiv2::kpsXMP);
42
30.3k
    image->printStructure(buffer, Exiv2::kpsRecursive);
43
30.3k
    image->printStructure(buffer, Exiv2::kpsIccProfile);
44
30.3k
    image->printStructure(buffer, Exiv2::kpsIptcErase);
45
46
30.3k
    image->writeMetadata();
47
48
30.3k
  } catch (...) {
49
    // Exiv2 throws an exception if the metadata is invalid.
50
28.7k
  }
51
52
30.3k
  return 0;
53
30.3k
}