@@ -16,7 +16,7 @@ import (
16
16
"github.com/AlecAivazis/survey/v2"
17
17
"github.com/containerd/containerd/identifiers"
18
18
"github.com/lima-vm/lima/pkg/limayaml"
19
- "github.com/lima-vm/lima/pkg/networks/reconcile"
19
+ networks "github.com/lima-vm/lima/pkg/networks/reconcile"
20
20
"github.com/lima-vm/lima/pkg/osutil"
21
21
"github.com/lima-vm/lima/pkg/start"
22
22
"github.com/lima-vm/lima/pkg/store"
@@ -53,6 +53,8 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
53
53
err error
54
54
)
55
55
56
+ const yBytesLimit = 4 * 1024 * 1024 // 4MiB
57
+
56
58
if argSeemsHTTPURL (arg ) {
57
59
instName , err = instNameFromHTTPURL (arg )
58
60
if err != nil {
@@ -64,7 +66,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
64
66
return nil , err
65
67
}
66
68
defer resp .Body .Close ()
67
- yBytes , err = io . ReadAll (resp .Body )
69
+ yBytes , err = readAtMaximum (resp .Body , yBytesLimit )
68
70
if err != nil {
69
71
return nil , err
70
72
}
@@ -74,7 +76,12 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
74
76
return nil , err
75
77
}
76
78
logrus .Debugf ("interpreting argument %q as a file path for instance %q" , arg , instName )
77
- yBytes , err = os .ReadFile (arg )
79
+ r , err := os .Open (arg )
80
+ if err != nil {
81
+ return nil , err
82
+ }
83
+ defer r .Close ()
84
+ yBytes , err = readAtMaximum (r , yBytesLimit )
78
85
if err != nil {
79
86
return nil , err
80
87
}
@@ -299,3 +306,17 @@ func startBashComplete(cmd *cobra.Command, args []string, toComplete string) ([]
299
306
instances , _ := bashCompleteInstanceNames (cmd )
300
307
return instances , cobra .ShellCompDirectiveDefault
301
308
}
309
+
310
+ func readAtMaximum (r io.Reader , n int64 ) ([]byte , error ) {
311
+ lr := & io.LimitedReader {
312
+ R : r ,
313
+ N : n ,
314
+ }
315
+ b , err := io .ReadAll (lr )
316
+ if err != nil {
317
+ if errors .Is (err , io .EOF ) && lr .N <= 0 {
318
+ err = fmt .Errorf ("exceeded the limit (%d bytes): %w" , n , err )
319
+ }
320
+ }
321
+ return b , err
322
+ }
0 commit comments