Coverage Report

Created: 2025-11-11 06:55

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
21.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
21.3k
  Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);
10
11
21.3k
  Exiv2::XmpParser::initialize();
12
21.3k
  ::atexit(Exiv2::XmpParser::terminate);
13
14
21.3k
  try {
15
21.3k
    Exiv2::DataBuf data_copy(data, size);
16
21.3k
    Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(data_copy.c_data(), size);
17
21.3k
    assert(image.get() != 0);
18
19
21.3k
    image->readMetadata();
20
25.3M
    for (auto& md : image->exifData()) {
21
25.3M
      if (md.tagName().substr(0, 2) != "0x") {
22
453k
        md.print();
23
453k
        md.print(&image->exifData());
24
453k
      }
25
25.3M
    }
26
21.3k
    for (auto& md : image->iptcData()) {
27
1.10k
      if (md.tagName().substr(0, 2) != "0x") {
28
586
        md.print();
29
586
        md.print(&image->exifData());
30
586
      }
31
1.10k
    }
32
21.3k
    for (auto& md : image->xmpData()) {
33
8.31k
      if (md.tagName().substr(0, 2) != "0x") {
34
8.31k
        md.print();
35
8.31k
        md.print(&image->exifData());
36
8.31k
      }
37
8.31k
    }
38
39
    // Print to a std::ostringstream so that the fuzzer doesn't
40
    // produce lots of garbage on stdout.
41
21.3k
    std::ostringstream buffer;
42
21.3k
    image->printStructure(buffer, Exiv2::kpsNone);
43
21.3k
    image->printStructure(buffer, Exiv2::kpsBasic);
44
21.3k
    image->printStructure(buffer, Exiv2::kpsXMP);
45
21.3k
    image->printStructure(buffer, Exiv2::kpsRecursive);
46
21.3k
    image->printStructure(buffer, Exiv2::kpsIccProfile);
47
21.3k
    image->printStructure(buffer, Exiv2::kpsIptcErase);
48
49
21.3k
    image->writeMetadata();
50
51
21.3k
  } catch (...) {
52
    // Exiv2 throws an exception if the metadata is invalid.
53
20.2k
  }
54
55
21.3k
  return 0;
56
21.3k
}