Add fuzz target for previews#3505
Conversation
|
@mergify backport 0.28.x |
✅ Backports have been createdDetails
Cherry-pick of d114ebb has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
There was a problem hiding this comment.
Pull request overview
This PR adds a new fuzz target for testing preview metadata extraction functionality in Exiv2. The fuzz target simulates the preview extraction code path from the main application, helping identify potential crashes or errors when processing malformed image files.
Changes:
- Added new fuzz target
fuzz-preview.cppthat exercises the PreviewManager API - Integrated the new fuzz target into the CMake build system
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| fuzz/fuzz-preview.cpp | New fuzz target that reads image metadata and extracts preview properties |
| fuzz/CMakeLists.txt | Added build configuration for the new fuzz-preview target |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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"; | ||
| } |
There was a problem hiding this comment.
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.
| 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; |
839c5cb to
d114ebb
Compare
In response to a vulnerability in Exiv2 that was found in code that isn't covered by our current fuzz targets, we've added a new fuzz target named `fuzz-preview`: Exiv2/exiv2#3505
This fuzz target mimics this code:
exiv2/app/actions.cpp
Lines 584 to 616 in 45c8b18
I'll add it to OSS-Fuzz once it's merged.