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/flate: Close is not idempotent #27741

Open
dsnet opened this issue Sep 18, 2018 · 3 comments
Open

compress/flate: Close is not idempotent #27741

dsnet opened this issue Sep 18, 2018 · 3 comments

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Sep 18, 2018

The flate.Writer.Close should be an idempotent operation. Furthermore, it should disallow further calls to Write:

b := new(bytes.Buffer)
zw, _ := flate.NewWriter(b, 6)
fmt.Println(zw.Write([]byte("hello, world!")))
fmt.Println(zw.Close())
fmt.Println(zw.Write([]byte("hello, world!")))
fmt.Println(zw.Close())
fmt.Printf("%x\n", b.String())

Currently, this prints:

13 <nil>
<nil>
13 <nil>
<nil>
ca48cdc9c9d75128cf2fca495104040000ffff42e100020000ffff

I expect it to print something like:

13 <nil>
<nil>
0 flate: write on closed stream
<nil>
ca48cdc9c9d75128cf2fca495104040000ffff

Currently, allowing a Write after a Close results in a corrupted stream. The trailing 42e100020000ffff is indicative of a backwards reference to the previous block. However, this is invalid since the previous block terminated the stream with the FINAL bit set.

This hasn't been much of a problem in practice since almost all usages of flate are through gzip, which does have this property.

@bcmills bcmills added the NeedsFix label Sep 19, 2018
@bcmills bcmills added this to the Unplanned milestone Sep 19, 2018
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Sep 19, 2018

Do you have a change pending, or should this be “help wanted”?

@dsnet

This comment has been minimized.

Copy link
Member Author

@dsnet dsnet commented Sep 19, 2018

I have no pending change. Great change for interested contributor. I can review.

@dsnet dsnet added the help wanted label Sep 19, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Sep 20, 2018

Change https://golang.org/cl/136475 mentions this issue: compress/flate: Return error on closed stream write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.