From b5038350430aeeb17a5c0994e90b658fa72d8f36 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 13 Feb 2017 18:15:23 +0000 Subject: [PATCH] cmd/release: double-check gzip files are single streams Updates golang/go#19052 Change-Id: I453dd1cc6016bf137f25f4e5b7a772b2c1888279 Reviewed-on: https://go-review.googlesource.com/36913 Reviewed-by: Joe Tsai --- cmd/release/release.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/release/release.go b/cmd/release/release.go index db34d8ce..45498e30 100644 --- a/cmd/release/release.go +++ b/cmd/release/release.go @@ -10,6 +10,7 @@ package main import ( "archive/tar" "archive/zip" + "bufio" "bytes" "compress/gzip" "context" @@ -601,10 +602,39 @@ func (b *Build) writeFile(name string, r io.Reader) error { if err := f.Close(); err != nil { return err } + if strings.HasSuffix(name, ".gz") { + if err := verifyGzipSingleStream(name); err != nil { + return fmt.Errorf("error verifying that %s is a single-stream gzip: %v", name, err) + } + } b.logf("Wrote %q.", name) return nil } +// verifyGzipSingleStream verifies that the named gzip file is not +// a multi-stream file. See golang.org/issue/19052 +func verifyGzipSingleStream(name string) error { + f, err := os.Open(name) + if err != nil { + return err + } + defer f.Close() + br := bufio.NewReader(f) + zr, err := gzip.NewReader(br) + if err != nil { + return err + } + zr.Multistream(false) + if _, err := io.Copy(ioutil.Discard, zr); err != nil { + return fmt.Errorf("reading first stream: %v", err) + } + peek, err := br.Peek(1) + if len(peek) > 0 || err != io.EOF { + return fmt.Errorf("unexpected peek of %d, %v after first gzip stream", len(peek), err) + } + return nil +} + func addPrefix(prefix string, in []string) []string { var out []string for _, s := range in {