From 1419406e8dd828f12b4810286d701b2b87ccd7ee Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 31 May 2012 21:45:39 +0200 Subject: [PATCH] BITOP bug when called against non existing keys fixed. In the issue #529 an user reported a bug that can be triggered with the following code: flushdb set a "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" bitop or x a b The bug was introduced with the speed optimization in commit 8bbc076 that specializes every BITOP operation loop up to the minimum length of the input strings. However the computation of the minimum length contained an error when a non existing key was present in the input, after a key that was non zero length. This commit fixes the bug and adds a regression test for it. --- src/bitops.c | 1 + tests/unit/bitops.tcl | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/bitops.c b/src/bitops.c index d309b7afa..00192b92b 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -197,6 +197,7 @@ void bitopCommand(redisClient *c) { objects[j] = NULL; src[j] = NULL; len[j] = 0; + minlen = 0; continue; } /* Return an error if one of the keys is not a string. */ diff --git a/tests/unit/bitops.tcl b/tests/unit/bitops.tcl index c8f58ef1e..0e3403bfe 100644 --- a/tests/unit/bitops.tcl +++ b/tests/unit/bitops.tcl @@ -160,4 +160,10 @@ start_server {tags {"bitops"}} { catch {r bitop xor dest a b c d} e set e } {*ERR*} + + test {BITOP with empty string after non empty string (issue #529)} { + r flushdb + r set a "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + r bitop or x a b + } {32} } -- GitLab