@cryptotaxi247 / kubo / commits / 3574caede

fix: error when using huge json limit file

This error nicely instead of ooming when trying to use a json file so big it would oom.

Jorropo committed Nov 2, 2022 at 00:02 UTC 3574caede5305889b486e37159ad961e62effad6
1 file changed +4 -1
core/commands/swarm.go
+4 -1
@@ -422,7 +422,10 @@ Changes made via command line are persisted in the Swarm.ResourceMgr.Limits fiel
422 if file == nil {
423 return errors.New("expected a JSON file")
424 }
425 - if err := json.NewDecoder(file).Decode(&newLimit); err != nil {
425 +
426 + r := io.LimitReader(file, 32*1024*1024) // 32MiB
427 +
428 + if err := json.NewDecoder(r).Decode(&newLimit); err != nil {
429 return fmt.Errorf("decoding JSON as ResourceMgrScopeConfig: %w", err)
430 }
431 return libp2p.NetSetLimit(node.ResourceManager, node.Repo, scope, newLimit)