Skip to content

opts: reject CPU counts that do not fit in int64 - #7342

Open
SashaMIT wants to merge 1 commit into
docker:masterfrom
SashaMIT:fix/parse-cpus-int64-range
Open

SashaMIT wants to merge 1 commit into
docker:masterfrom
SashaMIT:fix/parse-cpus-int64-range

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

ParseCPUs turns a CPU count into nano-CPUs (n * 1e9) and then calls big.Int.Int64. That call keeps the low 64 bits. ParseCPUs("10000000000") returned -8446744073709551616 and a nil error. 9223372036.854775808 (2^63 nano-CPUs) came back as math.MinInt64.

Values that fit still parse. 9223372036.854775807 is math.MaxInt64. -9223372036.854775808 is math.MinInt64. One nano-CPU past either end now returns value is out of range.

docker run --cpus, docker update --cpus, service CPU limits, and Compose cpus all go through this function.

Release notes

- Reject `--cpus` values that do not fit in an int64.

Drafted with Grok 4.7. The code has not yet been reviewed by a human.

ParseCPUs multiplied the ratio by 1e9 and called Int64, which keeps the low 64 bits. 10000000000 CPUs came back as -8446744073709551616 and a nil error.

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant