Skip to content

Get 416 Client Error on some zip files #13

@drygdryg

Description

@drygdryg

remotezip raising remotezip.RemoteIOError on some files. For example, http://0x0.st/o5Pa.apk (it's unavailable for now, so I re-uploaded it to https://transfer.sh/get/rndzvr/test.apk)
Also uploaded it to GitHub as zip archive: test.zip

$ remotezip http://0x0.st/o5Pa.apk AndroidManifest.xml
Extracting AndroidManifest.xml...
Traceback (most recent call last):
  File "/.../venv/lib/python3.10/site-packages/remotezip.py", line 193, in fetch_fun
    res, headers = self.request(self.url, range_header, kwargs, self.session)
  File "/.../venv/lib/python3.10/site-packages/remotezip.py", line 184, in request
    res.raise_for_status()
  File "/.../venv/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 416 Client Error: Requested Range Not Satisfiable for url: http://0x0.st/o5Pa.apk

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/.../venv/bin/remotezip", line 43, in <module>
    extract_files(args.url, args.filename, args.dir)
  File "/.../venv/bin/remotezip", line 26, in extract_files
    zip.extract(fname, path=path)
  File "/usr/lib/python3.10/zipfile.py", line 1628, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/lib/python3.10/zipfile.py", line 1698, in _extract_member
    with self.open(member, pwd=pwd) as source, \
  File "/usr/lib/python3.10/zipfile.py", line 1530, in open
    fheader = zef_file.read(sizeFileHeader)
  File "/usr/lib/python3.10/zipfile.py", line 745, in read
    data = self._file.read(n)
  File "/.../venv/lib/python3.10/site-packages/remotezip.py", line 112, in read
    self.buffer = self.fetch_fun((self.buffer.position, self.buffer.position + fetch_size -1), stream=stream)
  File "/.../venv/lib/python3.10/site-packages/remotezip.py", line 196, in fetch_fun
    raise RemoteIOError(str(e))
remotezip.RemoteIOError: 416 Client Error: Requested Range Not Satisfiable for url: http://0x0.st/o5Pa.apk

I also tested this file with PartialZipBrowser, and it works fine:

$ pzb -g AndroidManifest.xml https://0x0.st/o5Pa.apk
Version: 9bfdde2b2456181045f74631683fba491d8bf4f2 - 38
libfragmentzip version: 0.64-aaf6fae83a0aa6f7aae1c94721857076d04a14e8-RELEASE
init pzb: https://0x0.st/o5Pa.apk
init done
getting: AndroidManifest.xml
100% [===================================================================================================>]
download succeeded

It looks like byte range calculation bug in remotezip.
I also sniffed traffic, generated by remotezip and PartialZibBrowser while downloading this file, in mitmproxy, this may help you.

  1. remotezip
    image
  2. PartialZipBrowser:
    image

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