From ed0fd649404dcdcdae403d0e62b555889ee4e6b9 Mon Sep 17 00:00:00 2001 From: Andy Balholm Date: Thu, 25 Jul 2019 08:50:51 -0700 Subject: [PATCH] Fix int overflow in test on 32-bit. On 32-bit systems, the random array indexes were sometimes negative as a result of converting an int64 to int. Fixes #7. --- brotli_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brotli_test.go b/brotli_test.go index c29e08d..8e3329c 100644 --- a/brotli_test.go +++ b/brotli_test.go @@ -308,7 +308,7 @@ func TestQuality(t *testing.T) { func TestDecodeFuzz(t *testing.T) { // Test that the decoder terminates with corrupted input. content := bytes.Repeat([]byte("hello world!"), 100) - src := rand.NewSource(0) + rnd := rand.New(rand.NewSource(0)) encoded, err := Encode(content, WriterOptions{Quality: 5}) if err != nil { t.Fatalf("Encode(<%d bytes>, _) = _, %s", len(content), err) @@ -319,7 +319,7 @@ func TestDecodeFuzz(t *testing.T) { for i := 0; i < 100; i++ { enc := append([]byte{}, encoded...) for j := 0; j < 5; j++ { - enc[int(src.Int63())%len(enc)] = byte(src.Int63() % 256) + enc[rnd.Intn(len(enc))] = byte(rnd.Intn(256)) } Decode(enc) }