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

zlib.error: Error -3 while decompressing data: invalid stored block lengths #3

Closed
brechtm opened this issue Mar 20, 2023 · 3 comments · Fixed by #4
Closed

zlib.error: Error -3 while decompressing data: invalid stored block lengths #3

brechtm opened this issue Mar 20, 2023 · 3 comments · Fixed by #4
Assignees
Labels
bug Something isn't working

Comments

@brechtm
Copy link

brechtm commented Mar 20, 2023

$ tldr --update
Updating tldr-pages cache...
pages       / windows  [####################################]  100%
pages       / osx      [####################################]  100%
pages       / common   [#####-------------------------------]   14%  00:00:06
Traceback (most recent call last):
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/main.py", line 59, in wrapper
    func(ctx, param, value)
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/main.py", line 80, in subcommand_update
    pages.update_cache()
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/pages.py", line 165, in update_cache
    for filename, manpage in fut:
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/click/_termui_impl.py", line 328, in generator
    for rv in self.iter:
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 608, in result_iterator
    yield fs.pop().result()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/pages.py", line 147, in to_manpage
    rendered_manpage = render_manpage(tldr_page.read_text())
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 2352, in read_text
    return strm.read()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 909, in read
    buf += self._read1(self.MAX_N)
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 999, in _read1
    data = self._decompressor.decompress(data, n)
zlib.error: Error -3 while decompressing data: invalid stored block lengths

Running this again, this happens at different points in the process. For example, on another run, it crashed at converting the linux man pages. And with another error message:

$ tldr --update
Updating tldr-pages cache...
pages       / windows  [####################################]  100%
pages       / osx      [####################################]  100%
pages       / common   [####################################]  100%
pages       / sunos    [####################################]  100%
pages       / android  [####################################]  100%
pages       / linux    [################################----]   91%  00:00:00
Traceback (most recent call last):
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/main.py", line 59, in wrapper
    func(ctx, param, value)
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/main.py", line 80, in subcommand_update
    pages.update_cache()
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/pages.py", line 165, in update_cache
    for filename, manpage in fut:
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/click/_termui_impl.py", line 328, in generator
    for rv in self.iter:
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 608, in result_iterator
    yield fs.pop().result()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/apps/hosted/tldr-man/.venv/lib/python3.10/site-packages/tldr_man/pages.py", line 147, in to_manpage
    rendered_manpage = render_manpage(tldr_page.read_text())
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 2352, in read_text
    return strm.read()
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 909, in read
    buf += self._read1(self.MAX_N)
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/zipfile.py", line 999, in _read1
    data = self._decompressor.decompress(data, n)
zlib.error: Error -3 while decompressing data: invalid distance too far back
@brechtm
Copy link
Author

brechtm commented Mar 20, 2023

I tried with Python 3.10.8, which does work! I don't know whether it's an issue with Python 3.10.1 or with my particular installation.

@superatomic superatomic added the bug Something isn't working label Mar 21, 2023
@superatomic
Copy link
Owner

Thank you for bringing this issue to my attention!

I was able to reproduce a similar error in tldr --update using Python 3.10.1 and Python 3.10.3, resulting in the following error messages:

  • zipfile.BadZipFile: Bad magic number for file header
  • zlib.error: Error -3 while decompressing data: invalid distance too far back
  • zlib.error: Error -3 while decompressing data: invalid code lengths set

The cause of this problem seems to be that read_text() method of zipfile.Path is not thread-safe. This is a known bug in the Python Standard Library, which was reported in python/cpython#86535 (bpo-42369) and was fixed in Python version 3.10.4.

Since tldr-man-client v1.1.0 introduced the use of multiple threads for tldr --update in #2, this issue has only been present in that version, and only when using Python versions 3.10.0, 3.10.1, 3.10.2, and 3.10.3.

Since this is a bug with certain Python versions, this issue can be resolved by updating pyproject.toml to depend on a python version of ^3.10.4 instead of just ^3.10.

@superatomic
Copy link
Owner

Thanks again for reporting this bug! The issue should be fixed in tldr-man-client v1.1.1 (PyPI, GitHub).

Please let me know if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants