-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Provide an interface for fuzzing sequence producer plugins #3551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,116 @@ | ||
| /* | ||
| * Copyright (c) Yann Collet, Meta Platforms, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under both the BSD-style license (found in the | ||
| * LICENSE file in the root directory of this source tree) and the GPLv2 (found | ||
| * in the COPYING file in the root directory of this source tree). | ||
| * You may select, at your option, one of the above-listed licenses. | ||
| */ | ||
|
|
||
| #ifndef EXAMPLE_SEQ_PROD_H | ||
| #define EXAMPLE_SEQ_PROD_H | ||
|
|
||
| #define ZSTD_STATIC_LINKING_ONLY | ||
| #include "zstd.h" | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* *** INTERFACE FOR FUZZING THIRD-PARTY SEQUENCE PRODUCER PLUGINS *** | ||
| * Fuzz-testing for the external sequence producer API was introduced in PR #3437. | ||
| * However, the setup in #3437 only allows fuzzers to exercise the implementation of the | ||
| * API itself (the code in the core zstd library which interacts with your plugin). | ||
| * | ||
| * This header defines an interface for plugin authors to link their code into the fuzzer | ||
| * build. Plugin authors can provide an object file implementing the symbols below, | ||
| * and those symbols will replace the default ones provided by #3437. | ||
| * | ||
| * To fuzz your plugin, follow these steps: | ||
| * - Build your object file with a recent version of clang. Building with gcc is not supported. | ||
| * - Build your object file using appropriate flags for fuzzing. For example: | ||
| * `-g -fno-omit-frame-pointer -fsanitize=undefined,address,fuzzer` | ||
| * - Build the fuzzer binaries with options corresponding to the flags you chose. Use --custom-seq-prod= to pass in your object file: | ||
| * `./fuzz.py build all --enable-fuzzer --enable-asan --enable-ubsan --cc clang --cxx clang++ --custom-seq-prod=your_object.o` | ||
| * | ||
| * An example implementation of this header is provided at tests/fuzz/seq_prod_fuzz_example/. | ||
| * Use these commands to fuzz with the example code: | ||
| * $ make corpora | ||
| * $ make -C seq_prod_fuzz_example/ | ||
| * $ python3 ./fuzz.py build all --enable-fuzzer --enable-asan --enable-ubsan --cc clang --cxx clang++ --custom-seq-prod=seq_prod_fuzz_example/example_seq_prod.o | ||
| * $ python3 ./fuzz.py libfuzzer simple_round_trip | ||
| */ | ||
|
|
||
| /* The fuzzer will call this function before each test-case. It should run any | ||
| * setup actions (such as starting a hardware device) needed for fuzzing. | ||
| * | ||
| * The fuzzer will assert() that the return value is zero. To signal an error, | ||
| * please return a non-zero value. */ | ||
| size_t FUZZ_seqProdSetup(void); | ||
|
|
||
| /* The fuzzer will call this function after each test-case. It should free | ||
| * resources aquired by FUZZ_seqProdSetup() to prevent leaks across test-cases. | ||
| * | ||
| * The fuzzer will assert() that the return value is zero. To signal an error, | ||
| * please return a non-zero value. */ | ||
| size_t FUZZ_seqProdTearDown(void); | ||
|
|
||
| /* The fuzzer will call this function before each test-case, only after calling | ||
| * FUZZ_seqProdSetup(), to obtain a sequence producer state which can be passed | ||
| * into ZSTD_registerSequenceProducer(). | ||
| * | ||
| * All compressions which are part of a test-case will share a single sequence | ||
| * producer state. Sharing the state object is safe because the fuzzers currently | ||
| * don't exercise the sequence producer API in multi-threaded scenarios. We may | ||
| * need a new approach in the future to support multi-threaded fuzzing. | ||
| * | ||
| * The fuzzer will assert() that the return value is not NULL. To signal an error, | ||
| * please return NULL. */ | ||
| void* FUZZ_createSeqProdState(void); | ||
|
|
||
| /* The fuzzer will call this function after each test-case. It should free any | ||
| * resources aquired by FUZZ_createSeqProdState(). | ||
| * | ||
| * The fuzzer will assert() that the return value is zero. To signal an error, | ||
| * please return a non-zero value. */ | ||
| size_t FUZZ_freeSeqProdState(void* sequenceProducerState); | ||
|
|
||
| /* This is the sequence producer function you would like to fuzz! It will receive | ||
| * the void* returned by FUZZ_createSeqProdState() on each invocation. */ | ||
| size_t FUZZ_thirdPartySeqProd(void* sequenceProducerState, | ||
| ZSTD_Sequence* outSeqs, size_t outSeqsCapacity, | ||
| const void* src, size_t srcSize, | ||
| const void* dict, size_t dictSize, | ||
| int compressionLevel, | ||
| size_t windowSize); | ||
|
|
||
| /* These macros are internal helpers. You do not need to worry about them. */ | ||
| #ifdef FUZZ_THIRD_PARTY_SEQ_PROD | ||
| #define FUZZ_SEQ_PROD_SETUP() \ | ||
| do { \ | ||
| FUZZ_ASSERT(FUZZ_seqProdSetup() == 0); \ | ||
| FUZZ_seqProdState = FUZZ_createSeqProdState(); \ | ||
| FUZZ_ASSERT(FUZZ_seqProdState != NULL); \ | ||
| } while (0) | ||
| #else | ||
| #define FUZZ_SEQ_PROD_SETUP() | ||
| #endif | ||
|
|
||
| #ifdef FUZZ_THIRD_PARTY_SEQ_PROD | ||
| #define FUZZ_SEQ_PROD_TEARDOWN() \ | ||
| do { \ | ||
| FUZZ_ASSERT(FUZZ_freeSeqProdState(FUZZ_seqProdState) == 0); \ | ||
| FUZZ_ASSERT(FUZZ_seqProdTearDown() == 0); \ | ||
| } while (0) | ||
| #else | ||
| #define FUZZ_SEQ_PROD_TEARDOWN() | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* EXAMPLE_SEQ_PROD_H */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.