Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Python cannot run Subpars larger than 2GiB because they are Zip64 formatted. #132

Open
thundergolfer opened this issue Jun 9, 2021 · 0 comments

Comments

@thundergolfer
Copy link

thundergolfer commented Jun 9, 2021

This is very unlikely to be fixed due to Subpar's maintenance status but it's good to document it here to potentially save others some debugging time.


Any .par written by Subpar using zipfile will be ZIP64 format whenever the file size exceeds ZIP64_LIMIT = (1 << 31) - 1. See https://github.com/python/cpython/blob/ffd87b7093109c279caf8e3ca060f408a102388a/Lib/zipfile.py#L56

As of Python 3.10 zipimport does not support ZIP64. The module function in question is _read_directory: https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/zipimport.py#L408-L468

On attempting to run the subpar like python3 foo.par you will get an obscure error:

can't find '__main__' module in /foo.par

If you do python3 -vv foo.par you will see a logline:

# zipimport: found 0 names in /abs/path/to/foo.par

Python's zipimport._read_directory has failed to find any files because it has incorrectly calculated the byte offset for the first ZIP record file. It has incorrectly calculated the byte offset because it does not understand ZIP64.


So if you see this error check the size of your .par.

par_size = ...
max_bytes = (1 << 31) -1
if max_bytes < par_size:
    print("bad news")

cc @ducthienbui97 who completed this bug investigation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant