Skip to content

Commit 06c012f

Browse files
authored
Merge pull request #22146 from k8s-infra-cherrypick-robot/cherry-pick-22131-to-release-3.6
[release-3.6] Set a reasonable value for `snapshotLimitByte`
2 parents 51b7a84 + 4d6d3e9 commit 06c012f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • server/etcdserver/api/rafthttp

server/etcdserver/api/rafthttp/http.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ const (
4343
// for not causing a read timeout.
4444
connReadLimitByte = 64 * 1024
4545

46-
// snapshotLimitByte limits the snapshot size to 1TB
47-
snapshotLimitByte = 1 * 1024 * 1024 * 1024 * 1024
46+
// snapshotLimitByte limits the size of the raft snapshot *message*
47+
// (metadata plus the small membership blob embedded in
48+
// raftpb.Snapshot.Data). It does NOT bound the actual database
49+
// snapshot, which is streamed separately as the rest of the request
50+
// body (see snapshotHandler.ServeHTTP and SaveDBFrom) and can be
51+
// arbitrarily large. 64MB leaves generous headroom over realistic
52+
// envelope sizes while avoiding a huge allocation from a corrupt or
53+
// malicious length prefix.
54+
snapshotLimitByte = 64 * 1024 * 1024
4855
)
4956

5057
var (
@@ -218,7 +225,9 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
218225
addRemoteFromRequest(h.tr, r)
219226

220227
dec := &messageDecoder{r: r.Body}
221-
// let snapshots be very large since they can exceed 512MB for large installations
228+
// This only decodes the raft message envelope; the actual database
229+
// snapshot bytes that follow in the body are read separately below
230+
// via h.snapshotter.SaveDBFrom and are not subject to this limit.
222231
m, err := dec.decodeLimit(snapshotLimitByte)
223232
from := types.ID(m.From).String()
224233
if err != nil {

0 commit comments

Comments
 (0)