Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(vulnfeeds): only fuzzy-match versions on component boundaries - #6482

Open
AnujYamdagni wants to merge 2 commits into
google:masterfrom
AnujYamdagni:fix/vulnfeeds-fuzzy-version-boundary
Open

AnujYamdagni wants to merge 2 commits into
google:masterfrom
AnujYamdagni:fix/vulnfeeds-fuzzy-version-boundary

Conversation

@AnujYamdagni

@AnujYamdagni AnujYamdagni commented Dec 1, 2026 •

Copy link
Copy Markdown

Overview

VersionToCommit could attach the wrong tag's commit to a version: "1.2" could match a lone v1.20.0 tag, and "rc1" could match a lone tag without a pre-release component.

Fixes #6462

Details

  • findFuzzyCommit accepts a tag only when it extends the version by whole components (rest == "" || rest[0] == '-'), so "1-2" still matches "1-2-0".
  • NormalizeVersion returns an error when nothing is left after dropping the leading pre-release labels. Label-only versions and tags are skipped instead of mapping to "".
  • A pre-release component must also end at a component boundary, so "1.8.0-rc" no longer fuzzy-matches "1.8.0-rc1".
  • Returning an error treats a label with no numeric version as unsupported. Python's normalize_tag keeps rc1 instead; please say if you'd prefer parity.

Testing

Go 1.27.4, linux/amd64, master at 507dc98:

  • go test -count=1 -run 'TestVersionToCommit|TestNormalizeVersion' ./git/ (in vulnfeeds/): on master, 6 new cases fail ("Only a pre-release label", "Only pre-release labels", "Several leading words that match a label", "Fuzzy match does not cross a component boundary", "Fuzzy match does not extend a pre-release label", "Pre-release label alone does not match a lone release tag"); with this change all pass.
  • go test -count=1 ./git/ ./conversion/... ./cmd/converters/...: ok.
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run ./git/...: 0 issues.

Not tested: a full conversion run against real CVE data.

This PR was AI-assisted.

VersionToCommit falls back to a fuzzy tag match when there is no exact
one, and the match uses a plain string prefix. "1.2" (normalized "1-2")
can therefore resolve to the commit of a lone v1.20.0 tag. Accept a
fuzzy match only when the tag extends the version by whole components,
so "1-2" still matches "1-2-0".

NormalizeVersion returns an empty string and no error for a version that
is only a pre-release label, such as "rc1". The empty version can fuzzy-
match a lone tag without a pre-release component, and label-only tags
collapse onto one empty key in the tag map. Return an error instead, so
these versions and tags are skipped.
Comment thread vulnfeeds/git/versions.go
if v.MatchesVersionText == normalizedVersionMatchesText && strings.HasPrefix(k, normalizedVersion) {
// Only extend the version by whole components: "1-2" may match "1-2-0", but not "1-20-0".
rest, isPrefix := strings.CutPrefix(k, normalizedVersion)
if v.MatchesVersionText == normalizedVersionMatchesText && isPrefix && (rest == "" || rest[0] == '-') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking note: this looks clean and fixes the component-boundary issue well. For future reference, the len(candidateTags) == 1 branch below will still let e.g. "1.2" fuzzy-match a lone v1.2.5 tag (unlike the multi-candidate -0 fallback)—fine to keep out of scope for this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Agreed, the single-candidate branch still accepts a lone tag that extends the version by any number of components, so "1.2" can match a lone v1.2.5. I left that out of this PR.

Comment thread vulnfeeds/git/versions.go Outdated
@@ -133,6 +135,10 @@ func NormalizeVersion(version string) (normalizedVersion string, e error) {
if validVersionText.MatchString(components[0]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an input has multiple label matches and no version number (e.g. "alpha-beta", "rc1-beta2", or "source-archive" matching "rc" twice), only the first component is dropped and NormalizeVersion still returns a bare label without error.

Looping here closes that gap (and also handles multi-word prefixes like "source-archive-1.0" → "1-0"), guaranteeing any non-error result starts with a numeric component:

Suggested change
if validVersionText.MatchString(components[0]) {
for len(components) > 0 && validVersionText.MatchString(components[0]) {

If we make this change, could we also add a test case like "alpha-beta" or "source-archive" to TestNormalizeVersion?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 22c1200. It now drops every leading label component, and TestNormalizeVersion has "alpha-beta" (error) and "source-archive-1.0" ("1-0"). Both fail without the loop and pass with it.

NormalizeVersion dropped only the first component that matched a
pre-release label, so "alpha-beta" normalized to "beta" without an
error, and "source-archive-1.0" (both words contain "rc") to "rc-1-0".
Drop leading label components until a numeric one, so a non-error
result always starts with a number.

This branch has not been deployed

No deployments
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.

vulnfeeds: VersionToCommit matches 1.2 to v1.20.0

2 participants