summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-03-15 13:52:29 +0100
committerantirez <antirez@gmail.com>2019-03-15 13:52:29 +0100
commit4208666797b5831eefc022ae46ab5747200cd671 (patch)
tree8121e6268fac7932c2a3b4f27ebfb0fb67bcfd17 /tests
parent9f13b2bd4967334b1701c6eccdf53760cb13f79e (diff)
downloadredis-4208666797b5831eefc022ae46ab5747200cd671.tar.gz
HyperLogLog: dense/sparse repr parsing fuzz test.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/hyperloglog.tcl29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/hyperloglog.tcl b/tests/unit/hyperloglog.tcl
index 7d36b7a35..6a9c47b11 100644
--- a/tests/unit/hyperloglog.tcl
+++ b/tests/unit/hyperloglog.tcl
@@ -115,6 +115,35 @@ start_server {tags {"hll"}} {
set e
} {*WRONGTYPE*}
+ test {Fuzzing dense/sparse encoding: Redis should always detect errors} {
+ for {set j 0} {$j < 10000} {incr j} {
+ r del hll
+ set items {}
+ set numitems [randomInt 3000]
+ for {set i 0} {$i < $numitems} {incr i} {
+ lappend items [expr {rand()}]
+ }
+ r pfadd hll {*}$items
+
+ # Corrupt it in some random way.
+ for {set i 0} {$i < 5} {incr i} {
+ set len [r strlen hll]
+ set pos [randomInt $len]
+ set byte [randstring 1 1 binary]
+ r setrange hll $pos $byte
+ # Don't modify more bytes 50% of times
+ if {rand() < 0.5} break
+ }
+
+ # Use the hyperloglog to check if it crashes
+ # Redis in some way.
+ catch {
+ r pfcount hll
+ r pfdebug getreg hll
+ }
+ }
+ }
+
test {PFADD, PFCOUNT, PFMERGE type checking works} {
r set foo bar
catch {r pfadd foo 1} e