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

When using the NewWriterV2 function for compressing data, an error occurs during decompression if the data size is an exact multiple of blocksize. #51

Closed
newacorn opened this issue Jul 28, 2024 · 0 comments

Comments

@newacorn
Copy link

newacorn commented Jul 28, 2024

Test

func TestBrotliWriteMultiplyBlockData(t *testing.T) {
	tmpW := brotli.NewWriterV2(nil, 4)
	blockSize := tmpW.BlockSize
	for i := 0; i < 5; i++ {
		t.Run("compress data length: "+strconv.Itoa(i*blockSize)+"bytes", func(t *testing.T) {
			dataStr := randomstring.HumanFriendlyString(i * blockSize)
			dataBytes := []byte(dataStr)
			buf := bytes.Buffer{}
			w := brotli.NewWriterV2(&buf, 4)
			n, err := w.Write(dataBytes)
			err = w.Close()
			assert.NoErr(t, err)
			assert.Eq(t, n, len(dataBytes))
			assert.NoErr(t, err)
			r := brotli.NewReader(&buf)
			dst := make([]byte, len(dataBytes)+1000)
			p := dst
			total := 0
			for {
				n1, err1 := r.Read(p)
				if err1 != nil {
					if err1 != io.EOF {
						t.Fatal(err1)
					}
					break
				}
				total += n1
				p = p[n1:]
			}
			assert.Eq(t, dataBytes, dst[:total])
		})
	}

}

sum

Respceting p‘s length the observed errors are: either a PADDING_1 error is returned during reading, or the io.EOF error is not correctly returned, resulting in incorrect decompression of data or an infinite loop.

Fix: matchfinder Encode method bug

@newacorn newacorn changed the title When using the NewWriterV2 function for compressing data, an error occurs during decompression if the data size is an exact multiple of 65536. When using the NewWriterV2 function for compressing data, an error occurs during decompression if the data size is an exact multiple of blocksize. Jul 28, 2024
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

No branches or pull requests

1 participant