Skip to content

[doc] zlib.h: windowBits Z_DATA_ERROR guarantee doesn't hold for raw or gzip #1298

Description

@JasonGross

zlib/zlib.h

Lines 866 to 873 in e3dc0a8

The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
instead. windowBits must be greater than or equal to the windowBits value
provided to deflateInit2() while compressing, or it must be equal to 15 if
deflateInit2() was not used. If a compressed stream with a larger window
size is given as input, inflate() will return with the error code
Z_DATA_ERROR instead of trying to allocate a larger window.

For raw and gzip streams, which don't declare a window size in the header, if the caller provides a large enough output buffer, then the decompression may succeed despite requiring a larger window size than provided; the Z_DATA_ERROR seems to be triggered only when match distance exceeds the window + already written data in the buffer.

I presume this is only an issue with the documentation and not with the code. (It confused my LLM, I figured I'd report it here in case clarifying the documentation is useful.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions