Skip to content

Commit 6f00a4e

Browse files
ianlancetaylorgopherbot
authored andcommitted
debug/buildinfo: don't crash on corrupt object file
If the length reported for the object file is more than the amount of data we actually read, then the count can tell us that there is sufficient remaining data but the slice operation can fail. No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #69066 Change-Id: I8d12ca8ade3330517ade45c7578b477772b7efd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/608517 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 7c54e02 commit 6f00a4e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/debug/buildinfo/buildinfo.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,14 @@ func searchMagic(x exe, start, size uint64) (uint64, error) {
380380
}
381381
if i%buildInfoAlign != 0 {
382382
// Found magic, but misaligned. Keep searching.
383-
data = data[(i+buildInfoAlign-1)&^(buildInfoAlign-1):]
383+
next := (i + buildInfoAlign - 1) &^ (buildInfoAlign - 1)
384+
if next > len(data) {
385+
// Corrupt object file: the remaining
386+
// count says there is more data,
387+
// but we didn't read it.
388+
return 0, errNotGoExe
389+
}
390+
data = data[next:]
384391
continue
385392
}
386393
// Good match!

0 commit comments

Comments
 (0)