You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Malformed RESP can cause junk responses to the application which cannot be caught. #1172
In a malfunctioning Redis server (long story) partial or malformed RESP responses were being returned. While ioredis can detect these issues (message: ParserError: Protocol error, got ... as reply type byte. Please report this.) the response is still being returned back to the application via a callback or promise. This is most likely the same as #1166
Here is a test case to reproduce the bug with a mock server:
import Redis from "../../lib/redis";
import { expect } from "chai";
import MockServer from "../helpers/mock_server_delay";
const errorTrigger = 4;
let callCount = 0;
describe("mal-formed", function () {
it("should not return mal-formed resp", async function () {
new MockServer(30000, (argv) => {
if (argv[0] === "get") {
// this will echo the key passed to GET, so GET A returns "A", GET B returns "B"
callCount += 1;
let out = `$${String(argv[1]).length}\r\n${String(argv[1])}\r\n`;
// until we get to the specified call count then it will return addtional mal-formed RESP
if (callCount === errorTrigger) {
// repeat the last command & lop off some control characters
out += out.slice(0,-3);
}
return MockServer.raw(out);
}
});
const redis = new Redis(30000);
// loop through 'a' to 'g'
let responses = '';
try {
for (let i = 97; i < 107; i += 1) {
responses += await redis.get(String.fromCharCode(i));
}
expect(responses).to.equal('abcdefghij');
} catch (e) {
throw new Error(e);
}
});
});
This results in the test not succeeding because responses was abcd$fghij not the expected abcdefghij. Similar issues persisted with callback style responses as well as promises.
I would expect that if a malformed response was detected this would never be returned to the application orthogonally to the error handling or response style.
Reacted by Guy Korland, Oleg, Alexkh-MA, Trey Tacon, Ryan, Garret Meier, Seth Sakamoto and Logan Davis
Activity
fix: reject length-prefixed strings that are not followed by CRLF (re…