MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

fuzz/fuzz-read-print-write.cpp:7–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <iostream>
6
7extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
8 // Invalid files generate a lot of warnings, so switch off logging.
9 Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);
10
11 Exiv2::XmpParser::initialize();
12 ::atexit(Exiv2::XmpParser::terminate);
13
14 try {
15 Exiv2::DataBuf data_copy(data, size);
16 Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(data_copy.c_data(), size);
17 assert(image.get() != 0);
18
19 image->readMetadata();
20 for (auto& md : image->exifData()) {
21 md.print(&image->exifData());
22 }
23 for (auto& md : image->iptcData()) {
24 md.print(&image->exifData());
25 }
26 for (auto& md : image->xmpData()) {
27 md.print(&image->exifData());
28 }
29
30 // Print to a std::ostringstream so that the fuzzer doesn't
31 // produce lots of garbage on stdout.
32 std::ostringstream buffer;
33 image->printStructure(buffer, Exiv2::kpsNone);
34 image->printStructure(buffer, Exiv2::kpsBasic);
35 image->printStructure(buffer, Exiv2::kpsXMP);
36 image->printStructure(buffer, Exiv2::kpsRecursive);
37 image->printStructure(buffer, Exiv2::kpsIccProfile);
38 image->printStructure(buffer, Exiv2::kpsIptcErase);
39
40 image->writeMetadata();
41
42 } catch (...) {
43 // Exiv2 throws an exception if the metadata is invalid.
44 }
45
46 return 0;
47}

Callers

nothing calls this directly

Calls 6

c_dataMethod · 0.80
getMethod · 0.80
readMetadataMethod · 0.45
printMethod · 0.45
printStructureMethod · 0.45
writeMetadataMethod · 0.45

Tested by

no test coverage detected