Skip to content

Commit b666f28

Browse files
committed
runtime: use 64 bit calculation in overLoadFactor
overLoadFactor used a uintptr for its calculations. When the number of potential buckets was large, perhaps due to a coding error or corrupt/malicious user input leading to a very large map size hint, this led to overflow on 32 bit systems. This overflow resulted in an infinite loop. Prevent it by always using a 64 bit calculation. Updates #20195 Change-Id: Iaabc710773cd5da6754f43b913478cc5562d89a2 Reviewed-on: https://go-review.googlesource.com/42185 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 00db0cb commit b666f28

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/runtime/hashmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ func hashGrow(t *maptype, h *hmap) {
985985
// overLoadFactor reports whether count items placed in 1<<B buckets is over loadFactor.
986986
func overLoadFactor(count int64, B uint8) bool {
987987
// TODO: rewrite to use integer math and comparison?
988-
return count >= bucketCnt && float32(count) >= loadFactor*float32((uintptr(1)<<B))
988+
return count >= bucketCnt && float32(count) >= loadFactor*float32((uint64(1)<<B))
989989
}
990990

991991
// tooManyOverflowBuckets reports whether noverflow buckets is too many for a map with 1<<B buckets.

0 commit comments

Comments
 (0)