]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
It's time for all of rng seed code to go. Goodbye
authorDario Pavlovic <dariop@fb.com>
Thu, 12 Sep 2019 20:10:34 +0000 (13:10 -0700)
committerDario Pavlovic <dariop@fb.com>
Thu, 12 Sep 2019 20:10:34 +0000 (13:10 -0700)
tests/fuzz/fuzz.h
tests/fuzz/fuzz.py
tests/fuzz/fuzz_helpers.h

index 8850025b0fd257297abc740148045c679e8fdbe7..6d53aa6d5c7f7de16e223fe2545e59cb63173490 100644 (file)
  *        test code paths which are only executed when contexts are reused.
  *        WARNING: Makes reproducing crashes much harder.
  *        Default: Not defined.
- * @param FUZZ_RNG_SEED_SIZE:
- *        The number of bytes of the source to look at when constructing a seed
- *        for the deterministic RNG. These bytes are discarded before passing
- *        the data to zstd functions. Every fuzzer initializes the RNG exactly
- *        once before doing anything else, even if it is unused.
- *        Default: 4.
  * @param DEBUGLEVEL:
  *        This is a parameter for the zstd library. Defining `DEBUGLEVEL=1`
  *        enables assert() statements in the zstd library. Higher levels enable
 #ifndef FUZZ_H
 #define FUZZ_H
 
-#ifndef FUZZ_RNG_SEED_SIZE
-#  define FUZZ_RNG_SEED_SIZE 4
-#endif
-
 #include <stddef.h>
 #include <stdint.h>
 
index faf8ce8aed32a05ab533d4cc4900c797b6a27ac1..c790c83739033848078d611319bf061f33047f3a 100755 (executable)
@@ -740,10 +740,8 @@ def gen(args):
             for name in os.listdir(samples):
                 samplename = abs_join(samples, name)
                 outname = abs_join(seed, name)
-                rng_seed = os.urandom(args.fuzz_rng_seed_size)
                 with open(samplename, 'rb') as sample:
                     with open(outname, 'wb') as out:
-                        out.write(rng_seed)
                         CHUNK_SIZE = 131072
                         chunk = sample.read(CHUNK_SIZE)
                         while len(chunk) > 0:
index 0ee85fc7e2ad8d9b3240a31c0a6fa8db0b7c14ef..3de917fd1263f2b5b48dc9a68c715da5c37619e2 100644 (file)
@@ -55,37 +55,6 @@ extern "C" {
 #define FUZZ_STATIC static
 #endif
 
-/**
- * Deterministically constructs a seed based on the fuzz input.
- * Consumes up to the first FUZZ_RNG_SEED_SIZE bytes of the input.
- */
-FUZZ_STATIC uint32_t FUZZ_seed(uint8_t const **src, size_t* size) {
-    uint8_t const *data = *src;
-    size_t const toHash = MIN(FUZZ_RNG_SEED_SIZE, *size);
-    *size -= toHash;
-    *src += toHash;
-    return XXH32(data, toHash, 0);
-}
-
-#define FUZZ_rotl32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
-
-FUZZ_STATIC uint32_t FUZZ_rand(uint32_t *state) {
-    static const uint32_t prime1 = 2654435761U;
-    static const uint32_t prime2 = 2246822519U;
-    uint32_t rand32 = *state;
-    rand32 *= prime1;
-    rand32 += prime2;
-    rand32 = FUZZ_rotl32(rand32, 13);
-    *state = rand32;
-    return rand32 >> 5;
-}
-
-/* Returns a random numer in the range [min, max]. */
-FUZZ_STATIC uint32_t FUZZ_rand32(uint32_t *state, uint32_t min, uint32_t max) {
-    uint32_t random = FUZZ_rand(state);
-    return min + (random % (max - min + 1));
-}
-
 #ifdef __cplusplus
 }
 #endif