Adding tests to handle empty size & uint64 overflow in parsing size.

PiperOrigin-RevId: 449876821
This commit is contained in:
Shambhavi Srivastava
2022-05-19 18:26:46 -07:00
committed by gVisor bot
parent 874ffd6a26
commit 1228e6c788
2 changed files with 11 additions and 2 deletions
+9 -2
View File
@@ -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
}
+2
View File
@@ -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)