mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
fuzz: add webp fuzzer
This commit is contained in:
1 parent
3cea27456c
commit
5db6a08b6a
2 files changed
+86
No files matched your search
@@ -24,6 +24,7 @@ json: test/data/*.json ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
|
|||||||
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
|
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
|
||||||
targa: test/data/*.tga
|
targa: test/data/*.tga
|
||||||
wbmp: test/data/*.wbmp
|
wbmp: test/data/*.wbmp
|
||||||
|
webp: test/data/*.webp ../webp_corpus/*.webp
|
||||||
xz: test/data/*.xz ../xz_corpus/*.xz
|
xz: test/data/*.xz ../xz_corpus/*.xz
|
||||||
zlib: test/data/*.zlib
|
zlib: test/data/*.zlib
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Copyright 2026 The Wuffs Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
|
||||||
|
// ----------------
|
||||||
|
|
||||||
|
// Silence the nested slash-star warning for the next comment's command line.
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wcomment"
|
||||||
|
|
||||||
|
/*
|
||||||
|
This fuzzer (the fuzz function) is typically run indirectly, by a framework
|
||||||
|
such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
|
||||||
|
|
||||||
|
When working on the fuzz implementation, or as a coherence check, defining
|
||||||
|
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
|
||||||
|
|
||||||
|
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN webp_fuzzer.c
|
||||||
|
./a.out ../../../test/data/*.webp
|
||||||
|
rm -f ./a.out
|
||||||
|
|
||||||
|
It should print "PASS", amongst other information, and exit(0).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||||
|
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||||
|
//
|
||||||
|
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||||
|
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||||
|
// compiling it.
|
||||||
|
#define WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
|
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||||
|
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||||
|
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||||
|
// functions have static storage.
|
||||||
|
//
|
||||||
|
// This can help the compiler ignore or discard unused code, which can produce
|
||||||
|
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||||
|
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||||
|
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||||
|
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||||
|
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||||
|
|
||||||
|
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||||
|
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||||
|
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||||
|
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||||
|
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||||
|
// modules we use makes that process explicit. Preprocessing means that such
|
||||||
|
// code simply isn't compiled.
|
||||||
|
#define WUFFS_CONFIG__MODULES
|
||||||
|
#define WUFFS_CONFIG__MODULE__BASE
|
||||||
|
#define WUFFS_CONFIG__MODULE__VP8
|
||||||
|
#define WUFFS_CONFIG__MODULE__WEBP
|
||||||
|
|
||||||
|
// If building this program in an environment that doesn't easily accommodate
|
||||||
|
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||||
|
// program to generate a stand-alone C file.
|
||||||
|
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||||
|
#include "../fuzzlib/fuzzlib.c"
|
||||||
|
#include "../fuzzlib/fuzzlib_image_decoder.c"
|
||||||
|
|
||||||
|
const char* //
|
||||||
|
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||||
|
wuffs_webp__decoder dec;
|
||||||
|
wuffs_base__status status = wuffs_webp__decoder__initialize(
|
||||||
|
&dec, sizeof dec, WUFFS_VERSION,
|
||||||
|
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||||
|
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||||
|
if (!wuffs_base__status__is_ok(&status)) {
|
||||||
|
return wuffs_base__status__message(&status);
|
||||||
|
}
|
||||||
|
return fuzz_image_decoder(
|
||||||
|
src, hash,
|
||||||
|
wuffs_webp__decoder__upcast_as__wuffs_base__image_decoder(&dec));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user