forked from kenzuya/unshackle
fix(downloader): fail closed on rnet content codings outside the old allowlist
The rnet branch zeroed content_length only for gzip/deflate/br, so an unknown coding (zstd, future tokens) kept a bogus length and, worse, the drop-the-partial-instead-of-Range-resuming guard could never fire on the rnet path because content_encoded stayed False. Use the same fail-closed _is_content_encoded check the requests branch uses.
This commit is contained in:
@@ -714,12 +714,11 @@ def download(
|
||||
# server ignored the slice's Range and sent the whole parent; writing that
|
||||
# as the segment would silently corrupt the merge, so fail the attempt
|
||||
raise IOError(f"expected 206 for byte-range segment, got {stream.status_code}")
|
||||
content_encoded = False
|
||||
if use_rnet:
|
||||
content_length = stream.content_length or 0
|
||||
ce = (stream.headers.get("Content-Encoding") or stream.headers.get("content-encoding") or "").lower()
|
||||
if ce in ("gzip", "deflate", "br"):
|
||||
content_length = 0
|
||||
content_encoded = _is_content_encoded(
|
||||
stream.headers.get("Content-Encoding") or stream.headers.get("content-encoding")
|
||||
)
|
||||
content_length = 0 if content_encoded else (stream.content_length or 0)
|
||||
else:
|
||||
content_encoded = _is_content_encoded(stream.headers.get("Content-Encoding"))
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user