File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -324,13 +324,21 @@ func APIAddr(repoPath string) (ma.Multiaddr, error) {
324
324
325
325
// read up to 2048 bytes. io.ReadAll is a vulnerability, as
326
326
// someone could hose the process by putting a massive file there.
327
- buf := make ([]byte , 2048 )
328
- n , err := f .Read (buf )
329
- if err != nil && err != io .EOF {
327
+ //
328
+ // NOTE(@stebalien): @jbenet probably wasn't thinking straight when he
329
+ // wrote that comment but I'm leaving the limit here in case there was
330
+ // some hidden wisdom. However, I'm fixing it such that:
331
+ // 1. We don't read too little.
332
+ // 2. We don't truncate and succeed.
333
+ buf , err := ioutil .ReadAll (io .LimitReader (f , 2048 ))
334
+ if err != nil {
330
335
return nil , err
331
336
}
337
+ if len (buf ) == 2048 {
338
+ return nil , fmt .Errorf ("API file too large, must be <2048 bytes long: %s" , apiFilePath )
339
+ }
332
340
333
- s := string (buf [: n ] )
341
+ s := string (buf )
334
342
s = strings .TrimSpace (s )
335
343
return ma .NewMultiaddr (s )
336
344
}
You can’t perform that action at this time.
0 commit comments