docker / docker/cli

testing: address G115: integer overflow conversion int issues and re-enable linter (gosec)

Open
#5,584 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/testing help wanted
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.