Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ endmacro()

FUZZER(fuzz-read-print-write)
FUZZER(fuzz-read-write)
FUZZER(fuzz-preview)
35 changes: 35 additions & 0 deletions fuzz/fuzz-preview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <exiv2/exiv2.hpp>

#include <cassert>
#include <iomanip>
#include <iostream>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Invalid files generate a lot of warnings, so switch off logging.
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);

try {
Exiv2::DataBuf data_copy(data, size);
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(data_copy.c_data(), size);
assert(image.get() != 0);

image->readMetadata();

Exiv2::PreviewManager pm(*image);
std::ostringstream os;
Exiv2::PreviewPropertiesList list = pm.getPreviewProperties();
for (const auto& pos : list) {
os << pos.mimeType_ << "\n";

if (pos.width_ != 0 && pos.height_ != 0)
os << pos.width_ << " " << pos.height_ << " ";

os << pos.size_ << "\n";
}
Comment on lines +19 to +28
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output written to the ostringstream is never used or validated. In a fuzz target, this creates unnecessary overhead. Consider removing the ostringstream entirely or using the output to exercise additional code paths if that's the intent.

Suggested change
std::ostringstream os;
Exiv2::PreviewPropertiesList list = pm.getPreviewProperties();
for (const auto& pos : list) {
os << pos.mimeType_ << "\n";
if (pos.width_ != 0 && pos.height_ != 0)
os << pos.width_ << " " << pos.height_ << " ";
os << pos.size_ << "\n";
}
Exiv2::PreviewPropertiesList list = pm.getPreviewProperties();
std::size_t preview_count = 0;
for (const auto& pos : list) {
// Touch the fields to ensure they are exercised without incurring
// the overhead of building an unused ostringstream.
if (pos.width_ != 0 && pos.height_ != 0) {
++preview_count;
}
preview_count += static_cast<std::size_t>(pos.size_ != 0);
}
(void)preview_count;

Copilot uses AI. Check for mistakes.

} catch (...) {
// Exiv2 throws an exception if the metadata is invalid.
}

return 0;
}