Skip to content

Commit

Permalink
fix: error when using huge json limit file
Browse files Browse the repository at this point in the history
This error nicely instead of ooming when trying to use a json file so big it would oom.
  • Loading branch information
Jorropo authored and lidel committed Nov 8, 2022
1 parent d69f7a5 commit 3574cae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ Changes made via command line are persisted in the Swarm.ResourceMgr.Limits fiel
if file == nil {
return errors.New("expected a JSON file")
}
if err := json.NewDecoder(file).Decode(&newLimit); err != nil {

r := io.LimitReader(file, 32*1024*1024) // 32MiB

if err := json.NewDecoder(r).Decode(&newLimit); err != nil {
return fmt.Errorf("decoding JSON as ResourceMgrScopeConfig: %w", err)
}
return libp2p.NetSetLimit(node.ResourceManager, node.Repo, scope, newLimit)
Expand Down

0 comments on commit 3574cae

Please sign in to comment.