aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/pack/pack.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2017-08-31 11:26:28 -0700
committerMatthew Dempsky <mdempsky@google.com>2017-09-09 14:13:33 +0000
commit3d7042fba341180e63ea27fdfafbbab2499314aa (patch)
treed37d63c05d68ddb554701fcddfd45b2e36addf32 /src/cmd/pack/pack.go
parent08347648a6261fddc259fd846cf565a03875416a (diff)
downloadgo-3d7042fba341180e63ea27fdfafbbab2499314aa.tar.xz
cmd/pack: fix export data truncation bug
The binary export data format includes escaping to prevent "\n$$" from appearing internally, but not "\n!\n". This could result in a false positive when cmd/pack searched for "\n!\n" as the delimiter between package definition and linker object. To address this, this CL changes cmd/pack to also be aware of the "\n$$" markers, and to ignore "\n!\n" within the export data. Fixes #21703. Change-Id: I71ea8ba49dbd066c7afb7717ddc0190e38fe5649 Reviewed-on: https://go-review.googlesource.com/60773 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/pack/pack.go')
-rw-r--r--src/cmd/pack/pack.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/pack/pack.go b/src/cmd/pack/pack.go
index 1c168f946b..3abc83e090 100644
--- a/src/cmd/pack/pack.go
+++ b/src/cmd/pack/pack.go
@@ -426,8 +426,15 @@ func readPkgdef(file string) (data []byte, err error) {
// Read from file, collecting header for __.PKGDEF.
// The header is from the beginning of the file until a line
// containing just "!". The first line must begin with "go object ".
+ //
+ // Note: It's possible for "\n!\n" to appear within the binary
+ // package export data format. To avoid truncating the package
+ // definition prematurely (issue 21703), we keep keep track of
+ // how many "$$" delimiters we've seen.
+
rbuf := bufio.NewReader(f)
var wbuf bytes.Buffer
+ markers := 0
for {
line, err := rbuf.ReadBytes('\n')
if err != nil {
@@ -436,9 +443,12 @@ func readPkgdef(file string) (data []byte, err error) {
if wbuf.Len() == 0 && !bytes.HasPrefix(line, []byte("go object ")) {
return nil, errors.New("not a Go object file")
}
- if bytes.Equal(line, []byte("!\n")) {
+ if markers%2 == 0 && bytes.Equal(line, []byte("!\n")) {
break
}
+ if bytes.HasPrefix(line, []byte("$$")) {
+ markers++
+ }
wbuf.Write(line)
}
return wbuf.Bytes(), nil