Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bugs with multi/exec when detect_buffers is enabled. #732

Closed
raydog opened this issue Apr 1, 2015 · 0 comments · Fixed by #733
Closed

Multiple bugs with multi/exec when detect_buffers is enabled. #732

raydog opened this issue Apr 1, 2015 · 0 comments · Fixed by #733

Comments

@raydog
Copy link
Contributor

raydog commented Apr 1, 2015

I noticed several bugs in 0.12.1 with detect_buffers logic inside a multi/exec block. These bugs can be reproduced with the following code:

var redis = require('redis');

function checkCallback(name) {
  return function (err, res) {
    if (err) {
      console.log(name, "::", err.stack);
      process.exit(1);
    }
    if (res) {
      console.log(name, "::", res);
    }
  };
}

var client = redis.createClient({detect_buffers: true});

client.hmset("FOO", {"alpha":1, "beta":2}, checkCallback("Hmset"));
client.hgetall("FOO", checkCallback("Correct: normal hgetall"));

// Wrong: mangles data into [ { '1': ',', a: ',', p: 'h', b: 'e', t: 'a', ',': '2' } ]
client.multi().hgetall("FOO").exec(checkCallback("Bad: hgetall in multi"));

// Wrong: returns both values as strings, even though 'beta' wanted a buffer
client.multi()
  .hget("FOO", "alpha")
  .hget(new Buffer("FOO"), "beta")
  .exec(checkCallback("Bad: incorrect types for hget in multi"));

// Crashes due to attempting to do a .toString('binary') on a number
client.multi().hgetall(new Buffer("FOO")).exec(checkCallback("Bad: binary hgetall in multi"));

I'll attach a pull request to fix these bugs in a short bit. Thanks for the library!

Also: this is a duplicate of bug #263, but that issue hasn't been touched since mid-2013, so I elected to start fresh. Also, the PR I'll attach doesn't touch the parser, so it shouldn't conflict with hiredis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants