Unable to compress correctly if input data does not start from 0.
deshanxiao opened this issue · 5 comments
deshanxiao commented
Describe the bug
Unable to compress correctly if input data does not start from 0.
To Reproduce
Call Encoder.compress(byte[] x, int offset, int length) will compress all bytes from x
(offset > 0)
data.length -> length ?
Expected behavior
It should only compress the bytes from start to start + len.
Platform (please complete the following information):
ubuntu
Additional context
hyperxpro commented
What is the error? Are you getting corrupted data?
hyperxpro commented
Technically, you should compress all data and then finish the encoding with length 0
.
deshanxiao commented
I got no error but the output array looks unexpected in length. Here is a very simple example: @hyperxpro
public class Main2 {
static {
Brotli4jLoader.ensureAvailability();
}
public static void main(String[] args) throws IOException {
byte[] totalBytes = "abcdefg".getBytes();
// compress "defg"
byte[] compressedBytes = Encoder.compress(totalBytes, 3, 4);
// len(output) == 7 not 4
byte[] output = Decoder.decompress(compressedBytes, 0, compressedBytes.length);
}
}
hyperxpro commented
Okay, looks like a bug.
Would you like to raise a PR at https://github.com/google/brotli?
hyperxpro commented
PTAL