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

Assert fails with Z_HUFFMAN_ONLY #172

Closed
vinniefalco opened this issue Oct 25, 2016 · 10 comments
Closed

Assert fails with Z_HUFFMAN_ONLY #172

vinniefalco opened this issue Oct 25, 2016 · 10 comments

Comments

@vinniefalco
Copy link

When I define DEBUG, ZLib is failing this assertion for one of my cases:

Assert(buf != (char*)0, "lost buf");

The assertion is from this line:
https://github.com/madler/zlib/blob/master/trees.c#L951

Is this something I should be worried about? If necessary, I can put together a stand-alone program that reproduces the defect but before I do that work I want to know if it is an actual problem. If I don't define DEBUG everything seems to work. Here is my test code:
https://github.com/vinniefalco/Beast/blob/zlib/test/zlib/deflate_stream.cpp#L317

That line fails when level=0, windowBits=9, and strategy=2 (these are the parameters used in the call to deflateInit2).

vinniefalco added a commit to boostorg/beast that referenced this issue Oct 25, 2016
@madler
Copy link
Owner

madler commented Oct 25, 2016

Apparently it's not a problem, since it works without the assert. However I'm not sure what's going on there, so if you would be willing to put together something that reproduces the assertion, I would appreciate it. Thanks.

vinniefalco added a commit to boostorg/beast that referenced this issue Oct 25, 2016
@miguelportilla
Copy link

@madler I created a repo with minimal code that reproduces the assert when DEBUG is defined.

https://github.com/miguelportilla/zlib_test

@madler
Copy link
Owner

madler commented Oct 27, 2016

Thanks! There is a bug, but it is not serious. When you request stored (level 0) with the Huffman or RLE strategies, it can produce fixed or dynamic blocks. The output will always be valid deflate streams, but it just won't be entirely what was requested.

What's happening is that when it's time to emit a block, the Huffman or RLE code has been accumulating symbols and has slid the window back so that the beginning of the current block is no longer available. Since level 0 was requested, it goes to generate a stored block, at which point the assert is triggered. If it continues past the assert, then it determines that it can't emit a stored block, and emits a fixed or dynamic block instead.

@vinniefalco
Copy link
Author

So the assert can merely be commented out to no ill effect?

@madler
Copy link
Owner

madler commented Oct 27, 2016

Yes, for now. But the underlying bug needs to be fixed so that the application gets what it requested.

@vinniefalco
Copy link
Author

I would say that the "application not getting what it requested" certainly counts as "ill effect."

@madler
Copy link
Owner

madler commented Oct 27, 2016

Leaving the Assert in with debugging on certainly has ill effect, since then it simply fails when it could have produced valid deflate output. You can't even tell that it didn't give you what you asked for unless you examine the deflate output carefully with special tools (e.g. infgen). You didn't notice.

@vinniefalco
Copy link
Author

Oh so you still get something which, when inflated, gives you back the original plaintext? That's fine.

@madler
Copy link
Owner

madler commented Oct 27, 2016

Yes. You yourself noted that "If I don't define DEBUG everything seems to work."

@madler
Copy link
Owner

madler commented Oct 28, 2016

Bug fixed. See 9457585 . Thank you for the report.

@madler madler closed this as completed Oct 28, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 28, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 29, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 30, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 30, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 31, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Oct 31, 2016
vinniefalco referenced this issue in seelabs/Beast Nov 1, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Nov 1, 2016
vinniefalco added a commit to boostorg/beast that referenced this issue Nov 4, 2016
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

3 participants