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

bug in zstd : compression produces an invalid file with SpeedBestCompression #414

Closed
LeGEC opened this issue Aug 11, 2021 · 6 comments · Fixed by #415
Closed

bug in zstd : compression produces an invalid file with SpeedBestCompression #414

LeGEC opened this issue Aug 11, 2021 · 6 comments · Fixed by #415

Comments

@LeGEC
Copy link

LeGEC commented Aug 11, 2021

We hit a bug in the zstd package of this library : when compressing the attached file (the ungzipped version of that file) with level SpeedBestCompression, the compression succeeds without error, but the decompression fails with error "CRC check failed". The same error appears when trying to decompress with an external zstd decompressor.

This error did not appear in version 1.13.2 and appears in version 1.13.3.
In version 1.13.3, this error does not appear either when changing the compression level to any of the 3 other values.

Sample code :

func TestCompress(t *testing.T) {
	var b bytes.Buffer

	enc, err := zstd.NewWriter(&b, zstd.WithEncoderLevel(zstd.SpeedBestCompression))
	if err != nil {
		t.Fatal(err)
	}

	in, _ := os.Open("/tmp/failer.dat")
	_, err = io.Copy(enc, in)
	if err != nil {
		t.Fatal(err)
	}

	err = enc.Close()
	if err != nil {
		t.Fatal(err)
	}

	d, err := zstd.NewReader(&b)
	if err != nil {
		t.Fatal(err)
	}

	_, err = io.ReadAll(d)
	if err != nil {
		t.Fatal(err)  // test fails here : CRC check failed
	}
}
$ go version
go version go1.16.5 linux/amd64

failer.dat.gz

@klauspost
Copy link
Owner

@LeGEC Thanks for the report. I will investigate.

@LeGEC
Copy link
Author

LeGEC commented Aug 11, 2021

updated version range : this bug appeared between 1.13.2 and 1.13.3

@klauspost
Copy link
Owner

Yeah, likely #404

@klauspost
Copy link
Owner

Though it could be just because it creates different matches. Checking...

klauspost added a commit that referenced this issue Aug 11, 2021
Fix incorrect intermediate when testing current value for repeat+3 offsets.

Fixes #414
klauspost added a commit that referenced this issue Aug 11, 2021
Fix incorrect intermediate when testing current value for repeat+3 offsets.

Fixes #414
@klauspost
Copy link
Owner

Fix is in #415 - I will test and release.

klauspost added a commit that referenced this issue Aug 12, 2021
Fix incorrect intermediate when testing current value for repeat+3 offsets.

Fixes #414
@klauspost
Copy link
Owner

@LeGEC Released as 1.13.4. Thanks for the report!

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