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

Write errors are not returned from WriteTo for short compressed files #408

Closed
laurynasl-uber opened this issue Jul 13, 2021 · 3 comments · Fixed by #411
Closed

Write errors are not returned from WriteTo for short compressed files #408

laurynasl-uber opened this issue Jul 13, 2021 · 3 comments · Fixed by #411

Comments

@laurynasl-uber
Copy link

It seems that write errors from Decoder.WriteTo are not returned when the compressed input is short. This causes io.Copy calls to wrongly return success, even though a write has failed. See the test case below for an example.

type failingWriter struct {
	err error
}

func (f failingWriter) Write(_ []byte) (n int, err error) {
	return 0, f.err
}

func TestErrorWriter(t *testing.T) {
	input := make([]byte, 100)
	cmp := bytes.Buffer{}
	w, err := NewWriter(&cmp)
	if err != nil {
		t.Fatal(err)
	}
	defer w.Close()
	_, _ = rand.Read(input)
	_, err = w.Write(input)
	if err != nil {
		t.Fatal(err)
	}
	wantErr := fmt.Errorf("i'm a failure")
	zr, err := NewReader(&cmp)
	defer zr.Close()
	out := failingWriter{err: wantErr}
	_, err = zr.WriteTo(out)
	if !errors.Is(err, wantErr) {
		t.Errorf("error: wanted: %v, got: %v", wantErr, err)
	}
}

Test output:

=== RUN   TestErrorWriter
    decoder_test.go:195: error: wanted: i'm a failure, got: <nil>
--- FAIL: TestErrorWriter (0.00s)
@klauspost
Copy link
Owner

I am AFC and will be for a few weeks. Just to confirm, you are using the latest version? I seem to recall something like this a while back.

@laurynasl-uber
Copy link
Author

Yes, the test output included is from running on latest master

klauspost added a commit that referenced this issue Aug 2, 2021
Fix error forwarding when writing the final block.

Fixes #408
klauspost added a commit that referenced this issue Aug 2, 2021
Fix error forwarding when writing the final block.

Fixes #408
klauspost added a commit that referenced this issue Aug 2, 2021
Fix error forwarding when writing the final block.

Fixes #408
klauspost added a commit that referenced this issue Aug 2, 2021
Fix error forwarding when writing the final block.

Fixes #408
@laurynasl-uber
Copy link
Author

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants