go/src/debug/buildinfo
Michael Pratt 61e00ae134 debug/buildinfo: stop searchMagic search at EOF
An invalid executable may claim to have a data section bigger than the
executable, causing readData in searchMagic to hit EOF. Since readData
suppresses all EOF errors, searchData would keep attempting to search
through a potentially huge "section" despite readData continuously
failing.

Fix by suppressing EOF only on partial read. If nothing is read, allow
EOF. Note that most of the admittedly tedious EOF handling in this
package is around ensuring we return errNotGoExe in most cases.

This was discovered by the new fuzz test. This fuzz test was inspired
by #69066, though it has not found that specific bug.

Change-Id: Icf413e996cecc583c084c9e44249b9294c3d8f10
Reviewed-on: https://go-review.googlesource.com/c/go/+/608637
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-27 17:29:18 +00:00
..
testdata debug/buildinfo: stop searchMagic search at EOF 2024-08-27 17:29:18 +00:00
buildinfo.go debug/buildinfo: stop searchMagic search at EOF 2024-08-27 17:29:18 +00:00
buildinfo_test.go debug/buildinfo: stop searchMagic search at EOF 2024-08-27 17:29:18 +00:00
search_test.go debug/buildinfo: reuse buffer in searchMagic 2024-07-31 14:26:42 +00:00