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

level 0 fake compression not supported #86

Closed
dktapps opened this issue Oct 10, 2020 · 5 comments · Fixed by #88
Closed

level 0 fake compression not supported #86

dktapps opened this issue Oct 10, 2020 · 5 comments · Fixed by #88

Comments

@dktapps
Copy link
Contributor

dktapps commented Oct 10, 2020

zlib supports a zero-compression mode under which the data is encapsulated uncompressed. libdeflate appears not to support this and segfaults when 0 is given as compression level.

@ebiggers
Copy link
Owner

Do you have a particular use case in mind for this? Just because zlib supports it doesn't necessarily mean it is useful.

Also FWIW, libdeflate_alloc_compressor() returns NULL when given an invalid compression level, i.e. 0, a negative number, or a number over 12. So if you are seeing a segfault, it's because your code isn't checking for NULL. (Looks like I forgot to document that failure case in libdeflate.h; I'll add it.)

@dktapps
Copy link
Contributor Author

dktapps commented Oct 10, 2020

In some places a zlib-wrapped stream is required even though we know the data can't be compressed effectively. This is in the context of a Minecraft Bedrock server, where the protocol unconditionally requires deflate-formatted data, although we may choose not to compress depending on the data.

From my experimentation I see that libdeflate already automatically chooses to not bother compressing in some cases, so this shouldn't be too difficult to expose as a level 0.

@dktapps
Copy link
Contributor Author

dktapps commented Oct 10, 2020

I guess this is more or less the same as #67 , although the way this is done in classic zlib world is letting the user provide a level 0 for compression.

ebiggers added a commit that referenced this issue Oct 10, 2020
Some users may require a valid DEFLATE, zlib, or gzip stream but know
ahead of time that particular inputs are not compressible.  zlib
supports "level 0" for this use case.  Support this in libdeflate too.

Resolves #86
ebiggers added a commit that referenced this issue Oct 11, 2020
Some users may require a valid DEFLATE, zlib, or gzip stream but know
ahead of time that particular inputs are not compressible.  zlib
supports "level 0" for this use case.  Support this in libdeflate too.

Resolves #86
ebiggers added a commit that referenced this issue Oct 11, 2020
Some users may require a valid DEFLATE, zlib, or gzip stream but know
ahead of time that particular inputs are not compressible.  zlib
supports "level 0" for this use case.  Support this in libdeflate too.

Resolves #86
@ebiggers
Copy link
Owner

Done in #88.

@dktapps
Copy link
Contributor Author

dktapps commented Oct 11, 2020

Thank you!

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

Successfully merging a pull request may close this issue.

2 participants