From c25edd44a04672573946138da9c8fdc8c0eef5fd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 23 Jan 2017 22:18:42 +0000 Subject: libgo: update to go1.8rc2 Fix a bug in the generation of the hash value in reflect.FuncOf. The merge script missed a bunch of testdata files over the years. Copy them over. Reviewed-on: https://go-review.googlesource.com/35570 From-SVN: r244835 --- libgo/go/compress/bzip2/bzip2_test.go | 24 +++++++++++++++--------- libgo/go/compress/flate/deflate.go | 7 +++++-- libgo/go/compress/flate/deflate_test.go | 31 +++++++++++++++++++++++++++++++ libgo/go/compress/flate/deflatefast.go | 19 +++++++++++++++++-- libgo/go/compress/gzip/issue14937_test.go | 14 ++++++++++---- 5 files changed, 78 insertions(+), 17 deletions(-) (limited to 'libgo/go/compress') diff --git a/libgo/go/compress/bzip2/bzip2_test.go b/libgo/go/compress/bzip2/bzip2_test.go index a6c3080..95fb1895 100644 --- a/libgo/go/compress/bzip2/bzip2_test.go +++ b/libgo/go/compress/bzip2/bzip2_test.go @@ -204,12 +204,6 @@ func TestMTF(t *testing.T) { } } -var ( - digits = mustLoadFile("testdata/e.txt.bz2") - twain = mustLoadFile("testdata/Mark.Twain-Tom.Sawyer.txt.bz2") - random = mustLoadFile("testdata/random.data.bz2") -) - func benchmarkDecode(b *testing.B, compressed []byte) { // Determine the uncompressed size of testfile. uncompressedSize, err := io.Copy(ioutil.Discard, NewReader(bytes.NewReader(compressed))) @@ -227,6 +221,18 @@ func benchmarkDecode(b *testing.B, compressed []byte) { } } -func BenchmarkDecodeDigits(b *testing.B) { benchmarkDecode(b, digits) } -func BenchmarkDecodeTwain(b *testing.B) { benchmarkDecode(b, twain) } -func BenchmarkDecodeRand(b *testing.B) { benchmarkDecode(b, random) } +func BenchmarkDecodeDigits(b *testing.B) { + digits := mustLoadFile("testdata/e.txt.bz2") + b.ResetTimer() + benchmarkDecode(b, digits) +} +func BenchmarkDecodeTwain(b *testing.B) { + twain := mustLoadFile("testdata/Mark.Twain-Tom.Sawyer.txt.bz2") + b.ResetTimer() + benchmarkDecode(b, twain) +} +func BenchmarkDecodeRand(b *testing.B) { + random := mustLoadFile("testdata/random.data.bz2") + b.ResetTimer() + benchmarkDecode(b, random) +} diff --git a/libgo/go/compress/flate/deflate.go b/libgo/go/compress/flate/deflate.go index 97265b3..4d6a535 100644 --- a/libgo/go/compress/flate/deflate.go +++ b/libgo/go/compress/flate/deflate.go @@ -136,14 +136,17 @@ func (d *compressor) fillDeflate(b []byte) int { delta := d.hashOffset - 1 d.hashOffset -= delta d.chainHead -= delta - for i, v := range d.hashPrev { + + // Iterate over slices instead of arrays to avoid copying + // the entire table onto the stack (Issue #18625). + for i, v := range d.hashPrev[:] { if int(v) > delta { d.hashPrev[i] = uint32(int(v) - delta) } else { d.hashPrev[i] = 0 } } - for i, v := range d.hashHead { + for i, v := range d.hashHead[:] { if int(v) > delta { d.hashHead[i] = uint32(int(v) - delta) } else { diff --git a/libgo/go/compress/flate/deflate_test.go b/libgo/go/compress/flate/deflate_test.go index 521a260..fbea761 100644 --- a/libgo/go/compress/flate/deflate_test.go +++ b/libgo/go/compress/flate/deflate_test.go @@ -12,6 +12,7 @@ import ( "io" "io/ioutil" "reflect" + "runtime/debug" "sync" "testing" ) @@ -864,3 +865,33 @@ func TestBestSpeedMaxMatchOffset(t *testing.T) { } } } + +func TestMaxStackSize(t *testing.T) { + // This test must not run in parallel with other tests as debug.SetMaxStack + // affects all goroutines. + n := debug.SetMaxStack(1 << 16) + defer debug.SetMaxStack(n) + + var wg sync.WaitGroup + defer wg.Wait() + + b := make([]byte, 1<<20) + for level := HuffmanOnly; level <= BestCompression; level++ { + // Run in separate goroutine to increase probability of stack regrowth. + wg.Add(1) + go func(level int) { + defer wg.Done() + zw, err := NewWriter(ioutil.Discard, level) + if err != nil { + t.Errorf("level %d, NewWriter() = %v, want nil", level, err) + } + if n, err := zw.Write(b); n != len(b) || err != nil { + t.Errorf("level %d, Write() = (%d, %v), want (%d, nil)", level, n, err, len(b)) + } + if err := zw.Close(); err != nil { + t.Errorf("level %d, Close() = %v, want nil", level, err) + } + zw.Reset(ioutil.Discard) + }(level) + } +} diff --git a/libgo/go/compress/flate/deflatefast.go b/libgo/go/compress/flate/deflatefast.go index a1636a3..08298b7 100644 --- a/libgo/go/compress/flate/deflatefast.go +++ b/libgo/go/compress/flate/deflatefast.go @@ -60,7 +60,7 @@ func newDeflateFast() *deflateFast { func (e *deflateFast) encode(dst []token, src []byte) []token { // Ensure that e.cur doesn't wrap. if e.cur > 1<<30 { - *e = deflateFast{cur: maxStoreBlockSize, prev: e.prev[:0]} + e.resetAll() } // This check isn't in the Snappy implementation, but there, the caller @@ -265,6 +265,21 @@ func (e *deflateFast) reset() { // Protect against e.cur wraparound. if e.cur > 1<<30 { - *e = deflateFast{cur: maxStoreBlockSize, prev: e.prev[:0]} + e.resetAll() + } +} + +// resetAll resets the deflateFast struct and is only called in rare +// situations to prevent integer overflow. It manually resets each field +// to avoid causing large stack growth. +// +// See https://golang.org/issue/18636. +func (e *deflateFast) resetAll() { + // This is equivalent to: + // *e = deflateFast{cur: maxStoreBlockSize, prev: e.prev[:0]} + e.cur = maxStoreBlockSize + e.prev = e.prev[:0] + for i := range e.table { + e.table[i] = tableEntry{} } } diff --git a/libgo/go/compress/gzip/issue14937_test.go b/libgo/go/compress/gzip/issue14937_test.go index e76d47c..30c1390 100644 --- a/libgo/go/compress/gzip/issue14937_test.go +++ b/libgo/go/compress/gzip/issue14937_test.go @@ -9,11 +9,17 @@ import ( "testing" ) -// Per golang.org/issue/14937, check that every .gz file -// in the tree has a zero mtime. +// TestGZIPFilesHaveZeroMTimes checks that every .gz file in the tree +// has a zero MTIME. This is a requirement for the Debian maintainers +// to be able to have deterministic packages. +// +// See https://golang.org/issue/14937. func TestGZIPFilesHaveZeroMTimes(t *testing.T) { - if testing.Short() && testenv.Builder() == "" { - t.Skip("skipping in short mode") + // To avoid spurious false positives due to untracked GZIP files that + // may be in the user's GOROOT (Issue 18604), we only run this test on + // the builders, which should have a clean checkout of the tree. + if testenv.Builder() == "" { + t.Skip("skipping test on non-builder") } goroot, err := filepath.EvalSymlinks(runtime.GOROOT()) if err != nil { -- cgit v1.1