Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compress/gzip: hangs on gunzip #6550

Closed
krasin opened this issue Oct 8, 2013 · 6 comments
Closed

compress/gzip: hangs on gunzip #6550

krasin opened this issue Oct 8, 2013 · 6 comments
Milestone

Comments

@krasin
Copy link

krasin commented Oct 8, 2013

$ go version
go version devel +add507d4646f Tue Oct 08 13:13:40 2013 -0700 linux/amd64

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Download will_hang.gz data file
2. Either download go_gunzip.go or take the program from
http://play.golang.org/p/cvnOQmWTRc

3. Run it
go go_gunzip.go < will_crash.gz

What is the expected output?
Before io.Copy
After io.Copy
<exit status 0>

What do you see instead?

$ go run go_gunzip.go < will_hang.gz                                                 
                            
2013/10/08 21:49:51 Before io.Copy

it hangs forever, eats 100% of CPU and never completes.

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Ubuntu Linux 12.04 x86-64 (also tested on 13.04).

Which version are you using?  (run 'go version')

$ go version
go version devel +add507d4646f Tue Oct 08 13:13:40 2013 -0700 linux/amd64

Additional info:

I ran the program under gdb. Here is the example stack traces:

0x00000000004313c0 in compress/flate.(*decompressor).huffSym (f=0xc21006e000,
h=0xc21006e030, ~anon1=0, ~anon2=...)
    at /home/krasin/go/src/pkg/compress/flate/inflate.go:645
645                             chunk =
h.links[chunk>>huffmanValueShift][(f.b>>huffmanChunkBits)&h.linkMask]
(gdb) bt
#0  0x00000000004313c0 in compress/flate.(*decompressor).huffSym (f=0xc21006e000,
h=0xc21006e030, ~anon1=0, ~anon2=...)
    at /home/krasin/go/src/pkg/compress/flate/inflate.go:645
#1  0x000000000043038d in compress/flate.(*decompressor).huffmanBlock (f=0xc21006e000)
    at /home/krasin/go/src/pkg/compress/flate/inflate.go:395
#2  0x000000000042f8f4 in compress/flate.(*decompressor).Read (f=0xc21006e000, b=
[]uint8 = {...}, ~anon1=8192, ~anon2=...)
    at /home/krasin/go/src/pkg/compress/flate/inflate.go:275
#3  0x0000000000424b69 in compress/gzip.(*Reader).Read (z=0xc21005d000, p= []uint8 =
{...}, n=8192, err=...)
    at /home/krasin/go/src/pkg/compress/gzip/gunzip.go:207
#4  0x0000000000425f30 in io/ioutil.devNull.ReadFrom (r=..., n=102203392, err=...) at
/home/krasin/go/src/pkg/io/ioutil/ioutil.go:144
#5  0x0000000000425584 in io.Copy (dst=..., src=..., written=0, err=...) at
/home/krasin/go/src/pkg/io/io.go:348
#6  0x0000000000400ed8 in main.main () at /home/krasin/testdata/go_gunzip.go:22




0x000000000043228a in hash/crc32.update (crc=1794811569, tab=0xc210047000, p= []uint8 =
{...}, ~anon3=8192)
    at /home/krasin/go/src/pkg/hash/crc32/crc32.go:103
103             for _, v := range p {
(gdb) bt
#0  0x000000000043228a in hash/crc32.update (crc=1794811569, tab=0xc210047000, p=
[]uint8 = {...}, ~anon3=8192)
    at /home/krasin/go/src/pkg/hash/crc32/crc32.go:103
#1  0x000000000043234e in hash/crc32.Update (crc=1794811569, tab=0xc210047000, p=
[]uint8 = {...}, ~anon3=1794811569)
    at /home/krasin/go/src/pkg/hash/crc32/crc32.go:114
#2  0x00000000004323c6 in hash/crc32.(*digest).Write (d=0xc21000a230, p= []uint8 =
{...}, n=8192, err=...)
    at /home/krasin/go/src/pkg/hash/crc32/crc32.go:118
#3  0x0000000000424bd9 in compress/gzip.(*Reader).Read (z=0xc21005d000, p= []uint8 =
{...}, n=8192, err=...)
    at /home/krasin/go/src/pkg/compress/gzip/gunzip.go:208
#4  0x0000000000425f30 in io/ioutil.devNull.ReadFrom (r=..., n=184705024, err=...) at
/home/krasin/go/src/pkg/io/ioutil/ioutil.go:144
#5  0x0000000000425584 in io.Copy (dst=..., src=..., written=0, err=...) at
/home/krasin/go/src/pkg/io/io.go:348
#6  0x0000000000400ed8 in main.main () at /home/krasin/testdata/go_gunzip.go:22


P.S. There's also a false alarm from me here:
https://golang.org/issue/6549 Please, don't confuse this bug report
(which I believe to be real) and that one.

Attachments:

  1. go_gunzip.go (396 bytes)
  2. will_hang.gz (65536 bytes)
@krasin
Copy link
Author

krasin commented Oct 8, 2013

Comment 1:

Small update:
3. Run it
go go_gunzip.go < will_hang.gz

@ianlancetaylor
Copy link
Contributor

Comment 2:

Labels changed: added priority-soon, go1.2maybe, removed priority-triage.

@robpike
Copy link
Contributor

robpike commented Oct 8, 2013

Comment 3:

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Oct 8, 2013

Comment 4:

Labels changed: added go1.2, removed go1.2maybe.

Owner changed to @rsc.

Status changed to Started.

@krasin
Copy link
Author

krasin commented Oct 8, 2013

Comment 5:

in huffSym, http://tip.golang.org/src/pkg/compress/flate/inflate.go#L645
644 if n > huffmanChunkBits {
645   chunk = h.links[chunk>>huffmanValueShift][(f.b>>huffmanChunkBits)&h.linkMask]
646   n = uint(chunk & huffmanCountMask)
647 }
644: n == 10, huffmanChunkBits == 9
645: chunk is assigned to 0
646: n is assigned to 0
it means that huffSym produces a symbol w/o advancing the input.
My current understanding is that huffman tree is invalid and the fix would be to check
the huffman tree at the construction stage.

@rsc
Copy link
Contributor

rsc commented Oct 9, 2013

Comment 6:

This issue was closed by revision 8ba6deb.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants