Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions storage/remote/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func DecodeReadRequest(r *http.Request) (*prompb.ReadRequest, error) {
return nil, err
}

decodedLen, err := snappy.DecodedLen(compressed)
if err != nil {
return nil, err
}
if decodedLen > decodeReadLimit {
return nil, fmt.Errorf("snappy: decoded length %d exceeds limit %d", decodedLen, decodeReadLimit)
}

reqBuf, err := snappy.Decode(nil, compressed)
if err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions storage/remote/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"sync"
"testing"

Expand Down Expand Up @@ -690,6 +691,17 @@ func TestMergeLabels(t *testing.T) {
}
}

func TestDecodeReadRequestTooLarge(t *testing.T) {
// 5-byte snappy stream whose header claims 256 MiB decoded length,
// well above decodeReadLimit (32 MiB).
bomb := []byte{0x80, 0x80, 0x80, 0x80, 0x01}
req, err := http.NewRequest(http.MethodPost, "/", bytes.NewReader(bomb))
require.NoError(t, err)

_, err = DecodeReadRequest(req)
require.ErrorContains(t, err, "exceeds limit")
}

func TestDecodeWriteRequest(t *testing.T) {
buf, _, _, err := buildWriteRequest(nil, writeRequestFixture.Timeseries, nil, nil, nil, nil, "snappy")
require.NoError(t, err)
Expand Down