From 418fae2ab6974941d48d426b0451ce78ac9c1a46 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 3 May 2016 08:05:14 +0200 Subject: [PATCH] Do not use rand() within fseek(), it might break reproducibility. --- src/libzzuf/lib-stream.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libzzuf/lib-stream.c b/src/libzzuf/lib-stream.c index a0ab1eb..00138ff 100644 --- a/src/libzzuf/lib-stream.c +++ b/src/libzzuf/lib-stream.c @@ -399,6 +399,12 @@ static int const shuffle[256] = * status, then call the original function. If the new file position * lies outside the previous internal buffer, it means the buffer has * been invalidated, so we fuzz whatever's preloaded in it. + * + * It may also happen that the internal buffer is re-filled for no + * reason, as is the case on glibc versions from ca. 2015. Since we + * have no robust way of detecting this, we save the internal buffer + * to a temporary area and replace it with pseudorandom data, then + * check the data for changes after the fseek() call. */ #define ZZ_FSEEK(myfseek) \ @@ -418,7 +424,7 @@ static int const shuffle[256] = \ /* backup the internal stream buffer and replace it with * some random data in order to detect possible changes. */ \ - uint8_t seed = shuffle[(fd + rand()) & 0xff]; \ + uint8_t seed = shuffle[fd & 0xff]; \ uint8_t oldbuf[oldoff + oldcnt]; \ uint8_t *buf = get_streambuf_base(stream); \ for (int i = 0; i < oldoff + oldcnt; ++i) \