mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Adding tests to handle empty size & uint64 overflow in parsing size.
PiperOrigin-RevId: 449876821
This commit is contained in:
committed by
gVisor bot
parent
874ffd6a26
commit
1228e6c788
@@ -972,7 +972,14 @@ func parseSize(s string) (uint64, error) {
|
||||
count = count << 10
|
||||
s = s[:len(s)-1]
|
||||
}
|
||||
bytes, err := strconv.ParseUint(s, 10, 64)
|
||||
bytes = bytes * uint64(count)
|
||||
byteTmp, err := strconv.ParseUint(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0, linuxerr.EINVAL
|
||||
}
|
||||
// Check for overflow.
|
||||
bytes := byteTmp * uint64(count)
|
||||
if byteTmp != 0 && bytes/byteTmp != uint64(count) {
|
||||
return 0, fmt.Errorf("size overflow")
|
||||
}
|
||||
return bytes, err
|
||||
}
|
||||
|
||||
@@ -171,6 +171,8 @@ func TestParseSize(t *testing.T) {
|
||||
{"5P", (5 * 1024 * 1024 * 1024 * 1024 * 1024), false},
|
||||
{"5e", (5 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024), false},
|
||||
{"5e3", 0, true},
|
||||
{"", 0, true},
|
||||
{"9999999999999999P", 0, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
testname := fmt.Sprintf("%s", tt.s)
|
||||
|
||||
Reference in New Issue
Block a user