testing: address G115: integer overflow conversion int issues and re-enable linter (gosec)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
- related / same issue in moby: https://github.com/moby/moby/issues/48358
Description
Updating golangci-lint to the current version also includes some new linting rules around integer overflows. Most, if not all, of these are likely harmless, but we should evaluate each of them, and where possible either //nolint ignore them, or update the code.
opts/port.go:166:26: G115: integer overflow conversion int -> uint32 (gosec)
TargetPort: uint32(port.Int()),
^
opts/port.go:167:26: G115: integer overflow conversion uint64 -> uint32 (gosec)
PublishedPort: uint32(i),
^
cli/command/service/logs.go:115:32: G115: integer overflow conversion uint64 -> int (gosec)
maxLength = getMaxLength(int(replicas))
^
cli/compose/convert/service.go:464:16: G115: integer overflow conversion uint64 -> int (gosec)
retries = int(*healthcheck.Retries)
^
cli/compose/convert/service.go:491:22: G115: integer overflow conversion int -> uint64 (gosec)
attempts := uint64(policy.MaximumRetryCount)
^
cli/command/container/cp.go:112:36: G115: integer overflow conversion int -> uint (gosec)
fmt.Fprint(buf, aec.Column(uint(len(header)+1)))
^
cli/command/container/opts.go:623:31: G115: integer overflow conversion int64 -> uint64 (gosec)
IOMaximumBandwidth: uint64(copts.ioMaxBandwidth),
^
cli/command/container/stats_helpers.go:187:25: G115: integer overflow conversion int64 -> uint64 (gosec)
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals
^
cli/command/image/tree.go:195:18: G115: integer overflow conversion uint -> int (gosec)
nameWidth := int(width)
^
cli/command/service/progress/progress.go:344:42: G115: integer overflow conversion uint64 -> int (gosec)
writeOverallProgress(u.progressOut, int(running), int(replicas), rollback)
^
cli/command/service/progress/progress.go:305:45: G115: integer overflow conversion uint64 -> int (gosec)
writeOverallProgress(u.progressOut, 0, int(replicas), rollback)
^
cli/command/service/progress/progress.go:387:51: G115: integer overflow conversion int -> uint64 (gosec)
if u.done || replicas > maxProgressBars || uint64(mappedSlot) > replicas {
^
cli/command/service/progress/progress.go:578:20: G115: integer overflow conversion uint64 -> int (gosec)
concurrent: int(*service.Spec.Mode.ReplicatedJob.MaxConcurrent),
^
cli/command/service/progress/progress.go:579:20: G115: integer overflow conversion uint64 -> int (gosec)
total: int(*service.Spec.Mode.ReplicatedJob.TotalCompletions),
^
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the G115 findings listed in opts/port.go, cli/command/service/logs.go, cli/compose/convert/service.go, cli/command/container/cp.go, cli/command/container/opts.go, cli/command/container/stats_helpers.go, cli/command/image/tree.go, and cli/command/service/progress/progress.go. Review each conversion and either update the code or mark harmless cases as ignored, then rerun the updated golangci-lint checks; done means the listed findings are addressed and the linter is re-enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100