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

Cannot open zip64 file if Zip64EOCD record has additional data #126834

Open
VladRassokhin opened this issue Nov 14, 2024 · 3 comments · May be fixed by #126841
Open

Cannot open zip64 file if Zip64EOCD record has additional data #126834

VladRassokhin opened this issue Nov 14, 2024 · 3 comments · May be fixed by #126841
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@VladRassokhin
Copy link

VladRassokhin commented Nov 14, 2024

Bug report

Bug description:

"Zip64 end of central directory record" may have additional data in the "zip64 extensible data sector" field.
In that case, zipfile should use offset from "Zip64 end of central directory locator".
Now it's read but ignored.

def run_test():
    with zipfile.ZipFile("file-with-extended-zip64eocd-record.zip", allowZip64=True) as special_file: # This fails
        print("success")

Problem lies in following code:

    sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data)
    if sig != stringEndArchive64Locator:
        return endrec

    if diskno != 0 or disks > 1:
        raise BadZipFile("zipfiles that span multiple disks are not supported")

    # Assume no 'zip64 extensible data'
    fpin.seek(offset - sizeEndCentDir64Locator - sizeEndCentDir64, 2)
    data = fpin.read(sizeEndCentDir64)

While it should be:

    sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data)
    if sig != stringEndArchive64Locator:
        return endrec

    if diskno != 0 or disks > 1:
        raise BadZipFile("zipfiles that span multiple disks are not supported")

    fpin.seek(reloff, 0)
    data = fpin.read(sizeEndCentDir64)

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

@VladRassokhin VladRassokhin added the type-bug An unexpected behavior, bug, or error label Nov 14, 2024
@VladRassokhin
Copy link
Author

Hex output of the end of such file:

1faafa80: 504b 0606 3100 0000 0000 0000 0000 0000
1faafa90: 0000 0000 0000 0000 767e 0100 0000 0000
1faafaa0: 767e 0100 0000 0000 3063 a700 0000 0000
1faafab0: 5097 031f 0000 0000 04b7 5893 1e50 4b06
1faafac0: 0700 0000 0080 faaa 1f00 0000 0001 0000
1faafad0: 0050 4b05 06ff ffff ffff ffff ffff ffff
1faafae0: ffff ffff ff00 00                      

@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 14, 2024
@VladRassokhin
Copy link
Author

I can submit MR in a couple of days. Seems I've found a solution.

@VladRassokhin
Copy link
Author

VladRassokhin commented Nov 14, 2024

Here's a python script which is able to generate a zip64 archive with some data in the zip64 end-of-archive record:
https://gist.github.com/VladRassokhin/9299bb8fbe3169b96e7bc31f91553815
I've copied and adjusted zipfile.ZipFile._write_end_record

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
2 participants