Repository navigation
fix(worker): compare npm semver parts exactly and lint discarded strconv errors - #495
Merged
Merged
Conversation
…onv errors semverParts saturated oversized components at MaxUint64 and mapped invalid ones to 0 silently. Parts are now compared as canonical decimal strings. A ruleguard rule (gocritic) flags dropped strconv.Atoi/Parse* errors in non-test code; remaining sites handle the error or carry a reasoned nolint.
Coverage
Go by area
Web by area (lines)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
semverPartsininternal/worker/npm_metadata.goignored the error ofstrconv.ParseUint. A component above uint64 saturates at MaxUint64, so1.99999999999999999999.0and1.99999999999999999998.0compared equal when choosing the latest npm version. Other non-test code also dropped strconv errors (pnpm.go,cyclonedx.go,declarative/loader.go,bench/oabench/sysmon.go,gosumdb_serve.go,pyversion.go).Change
semverPartskeeps each part as a canonical decimal string (leading zeros trimmed,0for empty/non-numeric);compareNumericorders by length, then lexically. No overflow.scripts/lintrules/strconv.gorun through gocritic (.golangci.yaml) flagsx, _ = strconv.Atoi/Parse*(...)in non-test code (tests excluded). Adds thego-ruleguard/dslmodule for the rule file (build tagruleguard).lockfileVersionthat is not a number now returnsErrInvalid; cyclonedx CWE and yaml line skip on error; sysmon uses aparseFloathelper; regex/fits-bounded sites (gosumdb, pyversion) carry//nolint:gocriticwith the reason.Tests
Table cases in
TestCompareSemverfor overflow, leading zeros and non-numeric parts; they fail on the old code.Checks run
make fmt,make lint(0 issues),go test -short -racefor worker, declarative, proxy, sbom, pkg/lockfile, pkg/pyversion.