| 1 |
/* |
| 2 |
* Copyright (c) Yann Collet, Meta Platforms, Inc. |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* This source code is licensed under both the BSD-style license (found in the |
| 6 |
* LICENSE file in the root directory of this source tree) and the GPLv2 (found |
| 7 |
* in the COPYING file in the root directory of this source tree). |
| 8 |
* You may select, at your option, one of the above-listed licenses. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "fuzz_third_party_seq_prod.h" |
| 12 |
|
| 13 |
#include <assert.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
_Thread_local size_t threadLocalState; |
| 18 |
|
| 19 |
size_t FUZZ_seqProdSetup(void) { |
| 20 |
threadLocalState = 0; |
| 21 |
return 0; |
| 22 |
} |
| 23 |
|
| 24 |
size_t FUZZ_seqProdTearDown(void) { |
| 25 |
return 0; |
| 26 |
} |
| 27 |
|
| 28 |
void* FUZZ_createSeqProdState(void) { |
| 29 |
return calloc(1, sizeof(size_t)); |
| 30 |
} |
| 31 |
|
| 32 |
size_t FUZZ_freeSeqProdState(void* state) { |
| 33 |
free(state); |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
size_t FUZZ_thirdPartySeqProd( |
| 38 |
void* sequenceProducerState, |
| 39 |
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity, |
| 40 |
const void* src, size_t srcSize, |
| 41 |
const void* dict, size_t dictSize, |
| 42 |
int compressionLevel, |
| 43 |
size_t windowSize |
| 44 |
) { |
| 45 |
/* Try to catch unsafe use of the shared state */ |
| 46 |
size_t* const sharedStatePtr = (size_t*)sequenceProducerState; |
| 47 |
assert(*sharedStatePtr == threadLocalState); |
| 48 |
(*sharedStatePtr)++; threadLocalState++; |
| 49 |
|
| 50 |
/* Check that fallback is enabled when FUZZ_THIRD_PARTY_SEQ_PROD is defined */ |
| 51 |
return ZSTD_SEQUENCE_PRODUCER_ERROR; |
| 52 |
} |