Skip to content

Commit 70f3205

Browse files
authored
Merge pull request ethereum#1370 from maticnetwork/mardizzone/fixes
Limit bytes during response body read
2 parents 9adec02 + f08f2ea commit 70f3205

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

consensus/bor/heimdall/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ var (
3131
)
3232

3333
const (
34-
stateFetchLimit = 50
35-
apiHeimdallTimeout = 5 * time.Second
36-
retryCall = 5 * time.Second
34+
heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB
35+
stateFetchLimit = 50
36+
apiHeimdallTimeout = 5 * time.Second
37+
retryCall = 5 * time.Second
3738
)
3839

3940
type StateSyncEventsResponse struct {
@@ -455,8 +456,11 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte,
455456
return nil, nil
456457
}
457458

459+
// Limit the number of bytes read from the response body
460+
limitedBody := http.MaxBytesReader(nil, res.Body, heimdallAPIBodyLimit)
461+
458462
// get response
459-
body, err := io.ReadAll(res.Body)
463+
body, err := io.ReadAll(limitedBody)
460464
if err != nil {
461465
return nil, err
462466
}

0 commit comments

Comments
 (0)