1
0
mirror of https://github.com/golang/go synced 2024-11-12 10:00:25 -07:00

compress/flate: fix infinite loop on malformed data

Test using compress/gzip, because that's how the
data arrived.

Fixes #6550.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14441051
This commit is contained in:
Russ Cox 2013-10-09 08:37:06 -04:00
parent 158c56ef8a
commit 8ba6deb1ec
3 changed files with 35 additions and 0 deletions

View File

@ -644,6 +644,10 @@ func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) {
if n > huffmanChunkBits {
chunk = h.links[chunk>>huffmanValueShift][(f.b>>huffmanChunkBits)&h.linkMask]
n = uint(chunk & huffmanCountMask)
if n == 0 {
f.err = CorruptInputError(f.roffset)
return 0, f.err
}
}
if n <= f.nb {
f.b >>= n

View File

@ -7,7 +7,10 @@ package gzip
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"time"
)
type gunzipTest struct {
@ -302,3 +305,31 @@ func TestDecompressor(t *testing.T) {
}
}
}
func TestIssue6550(t *testing.T) {
f, err := os.Open("testdata/issue6550.gz")
if err != nil {
t.Fatal(err)
}
gzip, err := NewReader(f)
if err != nil {
t.Fatalf("NewReader(testdata/issue6550.gz): %v", err)
}
defer gzip.Close()
done := make(chan bool, 1)
go func() {
_, err := io.Copy(ioutil.Discard, gzip)
if err == nil {
t.Errorf("Copy succeeded")
} else {
t.Logf("Copy failed (correctly): %v", err)
}
done <- true
}()
select {
case <-time.After(1 * time.Second):
t.Errorf("Copy hung")
case <-done:
// ok
}
}

Binary file not shown.