Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@baobao1270
Copy link

Description

This PR fixes/supports raw mode of Deflate compression.

Details

When request with Accept-Encoding: deflate HTTP header, some CDNs may have an unusual behavior, which responds with the content compressed in raw Deflate mode with Content-Encoding: deflate header. This causes aria2 abort download with error message libz::inflate() failed. cause:incorrect header check.

As zlib Manual described:

EXTERN int ZEXPORT inflateInit2(z_streamp strm,
                                int  windowBits);

... It should be in the range 8..15 for this version of the library.
...
windowBits can also be –8..–15 for raw inflate. In this case, -windowBits determines the window size. inflate() will then process raw deflate data, not looking for a zlib or gzip header, not generating a check value, and not looking for any check values for comparison at the end of the stream.
...
windowBits can also be greater than 15 for optional gzip decoding.

This PR tries to fix this issue by try decompress the content twice. The first trial is in normal mode, which is same as the old behavior. If the first trial fails, it will try re-initialiaze GZipDecodingStreamFilter class with windowBits = -15. Then, if the second trial is failed, aria2 will abort download, same as the old behavior.

Related URLs / Issues

Test Result

On my laptop the fix passed test with make -j2 check:

PASS: aria2c
============================================================================
Testsuite summary for aria2 1.37.0
============================================================================
# TOTAL: 1
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

However, a new test file compressed in raw Deflate mode might be needed to add more coverage to this case. Please reach me if I need further actions.

@baobao1270 baobao1270 marked this pull request as ready for review November 28, 2024 18:23
Pideo1 added a commit to Pideo1/aria2 that referenced this pull request Apr 14, 2025
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 this pull request may close these issues.

libz::inflate() failed. cause:incorrect header check

1 participant