forked from libvips/libvips
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a generic buffer saver that attempts to save images in the format matching the input. This ensures that our fuzzers covers the following savers: `heifsave`, `ppmsave`, `radsave` and `tiffsave`.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <vips/vips.h> | ||
|
||
extern "C" int | ||
LLVMFuzzerInitialize(int *argc, char ***argv) | ||
{ | ||
vips_concurrency_set(1); | ||
return 0; | ||
} | ||
|
||
extern "C" int | ||
LLVMFuzzerTestOneInput(const guint8 *data, size_t size) | ||
{ | ||
VipsImage *image; | ||
void *buf; | ||
const char *loader, *loader_end; | ||
char *tmp, *suffix; | ||
size_t len; | ||
|
||
if (!(image = vips_image_new_from_buffer(data, size, "", nullptr))) | ||
return 0; | ||
|
||
if (image->Xsize > 100 || | ||
image->Ysize > 100 || | ||
image->Bands > 4) { | ||
g_object_unref(image); | ||
return 0; | ||
} | ||
|
||
if (vips_image_get_typeof(image, VIPS_META_LOADER) && | ||
vips_image_get_string(image, VIPS_META_LOADER, &loader)) { | ||
g_object_unref(image); | ||
return 0; | ||
} | ||
|
||
loader_end = g_strrstr(loader, "load"); | ||
g_assert(loader_end); | ||
|
||
tmp = g_strndup(loader, strlen(loader) - strlen(loader_end)); | ||
suffix = g_strconcat(".", tmp, NULL); | ||
g_free(tmp); | ||
|
||
if (strcmp(suffix, ".rad") == 0) { | ||
g_free(suffix); | ||
// .rad -> .hdr | ||
suffix = g_strdup(".hdr"); | ||
} | ||
else if (strcmp(suffix, ".heif") == 0) { | ||
g_free(suffix); | ||
// Set the default compression for heifsave to AV1 instead of HEVC | ||
suffix = g_strdup(".avif"); | ||
} | ||
|
||
if (vips_image_write_to_buffer(image, suffix, &buf, &len, nullptr)) { | ||
g_free(suffix); | ||
g_object_unref(image); | ||
return 0; | ||
} | ||
|
||
g_free(buf); | ||
g_free(suffix); | ||
g_object_unref(image); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters