Skip to content

fix: handle Go 1.26 GOEXPERIMENT version format change#10351

Merged
DmitriyLewen merged 2 commits intoaquasecurity:mainfrom
VedantMadane:fix/go126-goexperiment-version
Mar 17, 2026
Merged

fix: handle Go 1.26 GOEXPERIMENT version format change#10351
DmitriyLewen merged 2 commits intoaquasecurity:mainfrom
VedantMadane:fix/go126-goexperiment-version

Conversation

@VedantMadane
Copy link
Copy Markdown
Contributor

Description

Go 1.26 changed the format used to embed GOEXPERIMENT flags in the binary's build info from \ X:\ separator (Go <=1.25) to -X:\ separator (Go >=1.26). Trivy was failing to correctly parse the stdlib version from binaries built with Go 1.26 when GOEXPERIMENT flags are present.

Changes

  • Strip both GOEXPERIMENT separator formats when parsing stdlib version: \ X:foo\ (Go <=1.25) and -X:foo\ (Go >=1.26)
  • Extract version parsing logic to \parseStdlibVersion\ for testability
  • Add unit tests for both format variants

Testing

  • Added \TestParseStdlibVersion\ with test cases for plain version, Go <=1.25 format (\go1.25.3 X:nodwarf5), and Go >=1.26 format (\go1.26.0-X:nodwarf5)
  • Existing \goexperiment\ integration test continues to pass

Fixes #10350

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 10, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

Hello @VedantMadane
Thanks for your contribution!

left a comment. Take a look, when you have time, please.

Copy link
Copy Markdown
Contributor

@DmitriyLewen DmitriyLewen Mar 10, 2026

Choose a reason for hiding this comment

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

I think you can use export_test.go file for this test (instead of creating new file (parse_internal_test.go.)
e.g.

diff --git a/pkg/dependency/parser/golang/binary/export_test.go b/pkg/dependency/parser/golang/binary/export_test.go
index 3f361bc1e..2c0bb7545 100644
--- a/pkg/dependency/parser/golang/binary/export_test.go
+++ b/pkg/dependency/parser/golang/binary/export_test.go
@@ -13,3 +13,6 @@ func (p *Parser) ChooseMainVersion(version, ldflagsVersion, elfVersion string) s
 func (p *Parser) ELFSymbolVersion(r io.ReaderAt, name string) string {
 	return p.elfSymbolVersion(r, name)
 }
+
+
+var ParseStdlibVersion = parseStdlibVersion
\ No newline at end of file
diff --git a/pkg/dependency/parser/golang/binary/parse_internal_test.go b/pkg/dependency/parser/golang/binary/parse_internal_test.go
index bece0aeff..3a0102b8c 100644
--- a/pkg/dependency/parser/golang/binary/parse_internal_test.go
+++ b/pkg/dependency/parser/golang/binary/parse_internal_test.go
@@ -1,8 +1,9 @@
-package binary
+package binary_test
 
 import (
 	"testing"
 
+	"github.com/aquasecurity/trivy/pkg/dependency/parser/golang/binary"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -40,7 +41,7 @@ func TestParseStdlibVersion(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			got := parseStdlibVersion(tt.goVersion)
+			got := binary.ParseStdlibVersion(tt.goVersion)
 			assert.Equal(t, tt.want, got)
 		})
 	}

@VedantMadane VedantMadane force-pushed the fix/go126-goexperiment-version branch from d23bb60 to 1abf69a Compare March 11, 2026 04:51
Go 1.26 changed the GOEXPERIMENT format from ' X:' separator to '-X:'.
Strip both formats when parsing stdlib version from build info.

Fixes aquasecurity#10350
@DmitriyLewen
Copy link
Copy Markdown
Contributor

Hello @VedantMadane

I see that you did a rebase, but I don't see the suggested changes.
Let me know if you need my help.

Regards, Dmitriy

@DmitriyLewen DmitriyLewen added this pull request to the merge queue Mar 17, 2026
Merged via the queue into aquasecurity:main with commit f207ec6 Mar 17, 2026
14 checks passed
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.

bug(go): Go 1.26 GOEXPERIMENT version format change causes stdlib version parsing warning

4 participants