Fixes issue where a buffer larger than 4096

bytes cannot be read
This commit is contained in:
Eelco Cramer 2020-10-09 11:35:14 +02:00
parent b965d69fc9
commit 97bbed8a92
No known key found for this signature in database
GPG Key ID: 92BE398A20135E17
2 changed files with 18 additions and 2 deletions

View File

@ -55,10 +55,13 @@ func (r *Reader) Reset(rd io.Reader) {
}
func (r *Reader) ReadLine() ([]byte, error) {
line, err := r.readLine()
if err != nil {
line, err := r.rd.ReadBytes('\n')
if err != nil && err != io.EOF {
return nil, err
}
if len(line) == 0 {
return nil, fmt.Errorf("redis: reply is empty")
}
if isNilReply(line) {
return nil, Nil
}

View File

@ -27,6 +27,19 @@ func BenchmarkReader_ParseReply_Slice(b *testing.B) {
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false)
}
func TestReader_ReadLine(t *testing.T) {
original := bytes.Repeat([]byte("a"), 8192)
r := proto.NewReader(bytes.NewReader(original))
read, err := r.ReadLine()
if err != nil {
t.Errorf("Should be able to read the full buffer: %v", err)
}
if bytes.Compare(read, original) != 0 {
t.Errorf("Values must be equal: %q", read)
}
}
func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) {
buf := new(bytes.Buffer)
for i := 0; i < b.N; i++ {