Skip to content

Commit 62a471f

Browse files
prattmicpull[bot]
authored andcommitted
debug/buildinfo: add test for malformed strings
Updates #68592. Change-Id: I00c6c740ca0bdd19af24e08a219ec3c90196097e Reviewed-on: https://go-review.googlesource.com/c/go/+/601458 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent f7b0314 commit 62a471f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/debug/buildinfo/buildinfo_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ func TestReadFile(t *testing.T) {
134134
}
135135
}
136136

137+
damageStringLen := func(t *testing.T, name string) {
138+
data, err := os.ReadFile(name)
139+
if err != nil {
140+
t.Fatal(err)
141+
}
142+
i := bytes.Index(data, []byte("\xff Go buildinf:"))
143+
if i < 0 {
144+
t.Fatal("Go buildinf not found")
145+
}
146+
verLen := data[i+32:]
147+
binary.PutUvarint(verLen, 16<<40) // 16TB ought to be enough for anyone.
148+
if err := os.WriteFile(name, data, 0666); err != nil {
149+
t.Fatal(err)
150+
}
151+
}
152+
137153
goVersionRe := regexp.MustCompile("(?m)^go\t.*\n")
138154
buildRe := regexp.MustCompile("(?m)^build\t.*\n")
139155
cleanOutputForComparison := func(got string) string {
@@ -193,6 +209,15 @@ func TestReadFile(t *testing.T) {
193209
},
194210
wantErr: "not a Go executable",
195211
},
212+
{
213+
name: "invalid_str_len",
214+
build: func(t *testing.T, goos, goarch, buildmode string) string {
215+
name := buildWithModules(t, goos, goarch, buildmode)
216+
damageStringLen(t, name)
217+
return name
218+
},
219+
wantErr: "not a Go executable",
220+
},
196221
{
197222
name: "valid_gopath",
198223
build: buildWithGOPATH,

0 commit comments

Comments
 (0)