mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Fail on errors when building fuzzers
Fails on errors when building fuzzers with `fuzz.py` (adds `Werror`). Currently allows `declaration-after-statement`, `c++-compat` and `deprecated` as they are abundant in code (some fixes to `declaration-after-statement` are presented in this commit).
This commit is contained in:
@ -405,7 +405,12 @@ def build(args):
|
|||||||
cxxflags = shlex.split(args.cxxflags)
|
cxxflags = shlex.split(args.cxxflags)
|
||||||
mflags = shlex.split(args.mflags)
|
mflags = shlex.split(args.mflags)
|
||||||
# Flags to be added to both cflags and cxxflags
|
# Flags to be added to both cflags and cxxflags
|
||||||
common_flags = []
|
common_flags = [
|
||||||
|
'-Werror',
|
||||||
|
'-Wno-error=declaration-after-statement',
|
||||||
|
'-Wno-error=c++-compat',
|
||||||
|
'-Wno-error=deprecated' # C files are sometimes compiled with CXX
|
||||||
|
]
|
||||||
|
|
||||||
cppflags += [
|
cppflags += [
|
||||||
'-DDEBUGLEVEL={}'.format(args.debug),
|
'-DDEBUGLEVEL={}'.format(args.debug),
|
||||||
|
@ -28,12 +28,12 @@ void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer) { free(producer); }
|
|||||||
|
|
||||||
uint32_t FUZZ_dataProducer_uint32Range(FUZZ_dataProducer_t *producer, uint32_t min,
|
uint32_t FUZZ_dataProducer_uint32Range(FUZZ_dataProducer_t *producer, uint32_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
FUZZ_ASSERT(min <= max);
|
|
||||||
|
|
||||||
uint32_t range = max - min;
|
uint32_t range = max - min;
|
||||||
uint32_t rolling = range;
|
uint32_t rolling = range;
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
|
FUZZ_ASSERT(min <= max);
|
||||||
|
|
||||||
while (rolling > 0 && producer->size > 0) {
|
while (rolling > 0 && producer->size > 0) {
|
||||||
uint8_t next = *(producer->data + producer->size - 1);
|
uint8_t next = *(producer->data + producer->size - 1);
|
||||||
producer->size -= 1;
|
producer->size -= 1;
|
||||||
@ -79,11 +79,11 @@ int FUZZ_dataProducer_empty(FUZZ_dataProducer_t *producer) {
|
|||||||
|
|
||||||
size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize)
|
size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize)
|
||||||
{
|
{
|
||||||
newSize = newSize > producer->size ? producer->size : newSize;
|
const size_t effectiveNewSize = newSize > producer->size ? producer->size : newSize;
|
||||||
|
|
||||||
size_t remaining = producer->size - newSize;
|
size_t remaining = producer->size - effectiveNewSize;
|
||||||
producer->data = producer->data + remaining;
|
producer->data = producer->data + remaining;
|
||||||
producer->size = newSize;
|
producer->size = effectiveNewSize;
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,11 +44,12 @@ int main(int argc, char const **argv) {
|
|||||||
fprintf(stderr, "WARNING: No files passed to %s\n", argv[0]);
|
fprintf(stderr, "WARNING: No files passed to %s\n", argv[0]);
|
||||||
for (i = 0; i < files->tableSize; ++i) {
|
for (i = 0; i < files->tableSize; ++i) {
|
||||||
char const *fileName = files->fileNames[i];
|
char const *fileName = files->fileNames[i];
|
||||||
DEBUGLOG(3, "Running %s", fileName);
|
|
||||||
size_t const fileSize = UTIL_getFileSize(fileName);
|
size_t const fileSize = UTIL_getFileSize(fileName);
|
||||||
size_t readSize;
|
size_t readSize;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
|
DEBUGLOG(3, "Running %s", fileName);
|
||||||
|
|
||||||
/* Check that it is a regular file, and that the fileSize is valid.
|
/* Check that it is a regular file, and that the fileSize is valid.
|
||||||
* If it is not a regular file, then it may have been deleted since we
|
* If it is not a regular file, then it may have been deleted since we
|
||||||
* constructed the list, so just skip it, but return an error exit code.
|
* constructed the list, so just skip it, but return an error exit code.
|
||||||
|
@ -37,9 +37,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
FUZZ_ASSERT(dctx);
|
FUZZ_ASSERT(dctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, 10 * size);
|
size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, 10 * size);
|
||||||
void *rBuf = FUZZ_malloc(bufSize);
|
void *rBuf = FUZZ_malloc(bufSize);
|
||||||
|
|
||||||
size_t const dSize = ZSTD_decompressDCtx(dctx, rBuf, bufSize, src, size);
|
size_t const dSize = ZSTD_decompressDCtx(dctx, rBuf, bufSize, src, size);
|
||||||
if (!ZSTD_isError(dSize)) {
|
if (!ZSTD_isError(dSize)) {
|
||||||
/* If decompression was successful, the content size from the frame header(s) should be valid. */
|
/* If decompression was successful, the content size from the frame header(s) should be valid. */
|
||||||
@ -48,6 +48,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
FUZZ_ASSERT(expectedSize == ZSTD_CONTENTSIZE_UNKNOWN || expectedSize == dSize);
|
FUZZ_ASSERT(expectedSize == ZSTD_CONTENTSIZE_UNKNOWN || expectedSize == dSize);
|
||||||
}
|
}
|
||||||
free(rBuf);
|
free(rBuf);
|
||||||
|
}
|
||||||
|
|
||||||
FUZZ_dataProducer_free(producer);
|
FUZZ_dataProducer_free(producer);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ static size_t compress(uint8_t *dst, size_t capacity,
|
|||||||
return dstSize;
|
return dstSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t decompress(void* dst, size_t dstCapacity, void const* src, size_t srcSize, FUZZ_dataProducer_t* producer)
|
static size_t decompress(void* dst, size_t dstCapacity, void const* src, size_t srcSize, FUZZ_dataProducer_t* producer)
|
||||||
{
|
{
|
||||||
ZSTD_inBuffer in = {src, srcSize, 0};
|
ZSTD_inBuffer in = {src, srcSize, 0};
|
||||||
ZSTD_outBuffer out = {dst, dstCapacity, 0};
|
ZSTD_outBuffer out = {dst, dstCapacity, 0};
|
||||||
|
Reference in New Issue
Block a user