Skip to content

Commit 97bbed8

Browse files
committed
Fixes issue where a buffer larger than 4096
bytes cannot be read
1 parent b965d69 commit 97bbed8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

internal/proto/reader.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ func (r *Reader) Reset(rd io.Reader) {
5555
}
5656

5757
func (r *Reader) ReadLine() ([]byte, error) {
58-
line, err := r.readLine()
59-
if err != nil {
58+
line, err := r.rd.ReadBytes('\n')
59+
if err != nil && err != io.EOF {
6060
return nil, err
6161
}
62+
if len(line) == 0 {
63+
return nil, fmt.Errorf("redis: reply is empty")
64+
}
6265
if isNilReply(line) {
6366
return nil, Nil
6467
}

internal/proto/reader_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ func BenchmarkReader_ParseReply_Slice(b *testing.B) {
2727
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false)
2828
}
2929

30+
func TestReader_ReadLine(t *testing.T) {
31+
original := bytes.Repeat([]byte("a"), 8192)
32+
r := proto.NewReader(bytes.NewReader(original))
33+
read, err := r.ReadLine()
34+
if err != nil {
35+
t.Errorf("Should be able to read the full buffer: %v", err)
36+
}
37+
38+
if bytes.Compare(read, original) != 0 {
39+
t.Errorf("Values must be equal: %q", read)
40+
}
41+
}
42+
3043
func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) {
3144
buf := new(bytes.Buffer)
3245
for i := 0; i < b.N; i++ {

0 commit comments

Comments
 (0)