Skip to content

Commit af00524

Browse files
prattmicgopherbot
authored andcommitted
debug/buildinfo: base64-encode test binaries
Overzealous security scanners don't like the Go 1.17 binary because they think it has every 1.17 security vulnerability. base64-encode the binary to hide from them. I've also extended the instructions to make the binary easier to reproduce. Since we do the Go binary, we might as well do the C binary too, as it apparently makes some virus scanners unhappy. Fixes #71753. For #71734. For #71821. Change-Id: I6a6a636cccbf5312522f52f27f74eded64048fb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/651175 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 3b25b3c commit af00524

File tree

10 files changed

+20657
-29
lines changed

10 files changed

+20657
-29
lines changed

src/debug/buildinfo/buildinfo_test.go

+16-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/binary"
1212
"flag"
1313
"fmt"
14+
"internal/obscuretestdata"
1415
"internal/testenv"
1516
"os"
1617
"os/exec"
@@ -275,24 +276,16 @@ func TestReadFile(t *testing.T) {
275276

276277
// Test117 verifies that parsing of the old, pre-1.18 format works.
277278
func Test117(t *testing.T) {
278-
// go117 was generated for linux-amd64 with:
279-
//
280-
// main.go:
281-
//
282-
// package main
283-
// func main() {}
284-
//
285-
// GOTOOLCHAIN=go1.17 go mod init example.com/go117
286-
// GOTOOLCHAIN=go1.17 go build
287-
//
288-
// TODO(prattmic): Ideally this would be built on the fly to better
289-
// cover all executable formats, but then we need a network connection
290-
// to download an old Go toolchain.
291-
info, err := buildinfo.ReadFile("testdata/go117")
279+
b, err := obscuretestdata.ReadFile("testdata/go117/go117.base64")
292280
if err != nil {
293281
t.Fatalf("ReadFile got err %v, want nil", err)
294282
}
295283

284+
info, err := buildinfo.Read(bytes.NewReader(b))
285+
if err != nil {
286+
t.Fatalf("Read got err %v, want nil", err)
287+
}
288+
296289
if info.GoVersion != "go1.17" {
297290
t.Errorf("GoVersion got %s want go1.17", info.GoVersion)
298291
}
@@ -306,20 +299,14 @@ func Test117(t *testing.T) {
306299

307300
// TestNotGo verifies that parsing of a non-Go binary returns the proper error.
308301
func TestNotGo(t *testing.T) {
309-
// notgo was generated for linux-amd64 with:
310-
//
311-
// main.c:
312-
//
313-
// int main(void) { return 0; }
314-
//
315-
// cc -o notgo main.c
316-
//
317-
// TODO(prattmic): Ideally this would be built on the fly to better
318-
// cover all executable formats, but then we need to encode the
319-
// intricacies of calling each platform's C compiler.
320-
_, err := buildinfo.ReadFile("testdata/notgo")
302+
b, err := obscuretestdata.ReadFile("testdata/notgo/notgo.base64")
303+
if err != nil {
304+
t.Fatalf("ReadFile got err %v, want nil", err)
305+
}
306+
307+
_, err = buildinfo.Read(bytes.NewReader(b))
321308
if err == nil {
322-
t.Fatalf("ReadFile got nil err, want non-nil")
309+
t.Fatalf("Read got nil err, want non-nil")
323310
}
324311

325312
// The precise error text here isn't critical, but we want something
@@ -410,13 +397,13 @@ func TestIssue54968(t *testing.T) {
410397
}
411398

412399
func FuzzRead(f *testing.F) {
413-
go117, err := os.ReadFile("testdata/go117")
400+
go117, err := obscuretestdata.ReadFile("testdata/go117/go117.base64")
414401
if err != nil {
415402
f.Errorf("Error reading go117: %v", err)
416403
}
417404
f.Add(go117)
418405

419-
notgo, err := os.ReadFile("testdata/notgo")
406+
notgo, err := obscuretestdata.ReadFile("testdata/notgo/notgo.base64")
420407
if err != nil {
421408
f.Errorf("Error reading notgo: %v", err)
422409
}

src/debug/buildinfo/testdata/go117

-1.11 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
go117.base64 is a base64-encoded Go 1.17 hello world binary used to test
2+
debug/buildinfo of pre-1.18 buildinfo encoding.
3+
4+
The binary is base64 encoded to hide it from security scanners that believe a
5+
Go 1.17 is inherently insecure.
6+
7+
Generate go117.base64 with:
8+
9+
$ GOTOOLCHAIN=go1.17 GOOS=linux GOARCH=amd64 go build -trimpath
10+
$ base64 go117 > go117.base64
11+
$ rm go117
12+
13+
TODO(prattmic): Ideally this would be built on the fly to better cover all
14+
executable formats, but then we need a network connection to download an old Go
15+
toolchain.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module example.com/go117
2+
3+
go 1.17

src/debug/buildinfo/testdata/go117/go117.base64

+20,314
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
func main() {}

src/debug/buildinfo/testdata/notgo

-15.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
notgo.base64 is a base64-encoded C hello world binary used to test
2+
debug/buildinfo errors on non-Go binaries.
3+
4+
The binary is base64 encoded to hide it from security scanners that might not
5+
like it.
6+
7+
Generate notgo.base64 on linux-amd64 with:
8+
9+
$ cc -o notgo main.c
10+
$ base64 notgo > notgo.base64
11+
$ rm notgo
12+
13+
The current binary was built with "gcc version 14.2.0 (Debian 14.2.0-3+build4)".
14+
15+
TODO(prattmic): Ideally this would be built on the fly to better cover all
16+
executable formats, but then we need to encode the intricacies of calling each
17+
platform's C compiler.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
int main(void) {
6+
return 0;
7+
}

src/debug/buildinfo/testdata/notgo/notgo.base64

+278
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)