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

Unable to compress correctly if input data does not start from 0. #126

Closed
deshanxiao opened this issue Dec 28, 2023 · 5 comments · Fixed by #127
Closed

Unable to compress correctly if input data does not start from 0. #126

deshanxiao opened this issue Dec 28, 2023 · 5 comments · Fixed by #127

Comments

@deshanxiao
Copy link
Contributor

deshanxiao commented Dec 28, 2023

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)

encoder.push(EncoderJNI.Operation.FINISH, data.length);

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
Copy link
Owner

hyperxpro commented Dec 28, 2023

What is the error? Are you getting corrupted data?

@hyperxpro
Copy link
Owner

Technically, you should compress all data and then finish the encoding with length 0.

@deshanxiao
Copy link
Contributor Author

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
Copy link
Owner

Okay, looks like a bug.

Would you like to raise a PR at https://github.com/google/brotli?

@hyperxpro
Copy link
Owner

PTAL

google/brotli#1104

@hyperxpro hyperxpro linked a pull request Dec 28, 2023 that will close this issue
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