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

pyminizip.compress_multiple password won't work #25

Open
Meow-ops opened this issue Jun 7, 2018 · 6 comments
Open

pyminizip.compress_multiple password won't work #25

Meow-ops opened this issue Jun 7, 2018 · 6 comments

Comments

@Meow-ops
Copy link

Meow-ops commented Jun 7, 2018

When using pyminizip.compress_multiple, the input password does not work.

@veon82
Copy link
Contributor

veon82 commented Jun 12, 2018

pyminizip.compress_multiple(['file1','file2'], [], 'output.zip', 'password', 5) works fine for me

@bk-equityzen
Copy link

bk-equityzen commented Jul 9, 2018

I'm also having this issue starting from 0.2.3. It works in my shell, but i think when used by django it doesn't work?

Python v 2.7.15

@veon82
Copy link
Contributor

veon82 commented Nov 13, 2018

I'm also having this issue starting from 0.2.3. It works in my shell, but i think when used by django it doesn't work?

Python v 2.7.15

I also noticed some strange behaviors introduced from version 0.2.3.
The only change from version 0.2.2 was the build process (embedded zlib was actually used).
In PR #26 I tried to fix the build removing duplicated files from src folder and I upgraded embedded zlib to version 1.2.11.

Can you try to build the module from my branch and test if it solves your issues in django?

@wolfly22
Copy link

python:3.8.1
pyminizip:0.2.4

DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats

@Ailibert
Copy link

I also encountered the situation that the password does not work. Is there a good solution now?

@nebbish
Copy link

nebbish commented Aug 17, 2023

I just found this github issue -- after first experiencing the problem and investigating locally for a while first.

I am using this library in my work environment, where I need the password feature to work on Windows, Linux, and Mac.
It turns out for me, using version 0.2.6, that the password feature works fine on WIndows & Linux -- only Mac is broken. (tried with MacOS 13.4.1 and 12.4)


I even tried to ensure the "text" going through the Py-code was correctly getting passed into the zlib API, so I forked this repo, and added a trace statement in _compress of the final char* value before calling zipOpenNewFileInZip3_64 -- and it printed the password as I passed it in. 😕

So then I cloned my fork onto a MacOS Ventura 13.4.1 with the built-in Python 3.8 -- which has no xcode bits other than whatever comes default with the OS. The wheel built fine, and installed fine.
The trace showed the password fine --- but it still did not work! 😣


I see that this repository includes a copy of zlib 1.2.11 (i think just for the headers -- I'm kinda new to building wheels)
I wanted to check my MacOS to see which zlib actually got used at run-time -- but I'm also new to MacOS, not sure where to find the files. I am now running system wide finds to locate the headers & libraries that are already on my system so I can compile directly from my system. (still in progress)

So while I'm stuck waiting, I can at least I can share the small stand-alone PY script I've been using to validate the password feature:

import os, click, tempfile, pyminizip, zipfile

PWD = "wXGTZJ9L5C"  # from some pwd-generating web-site, just fodder for repro
data_files = { "one.txt" : b"hello world!\n", "two.txt" : b"booya kada\n" }

@click.command
@click.argument('password', default=PWD)
def cli(password):
    with tempfile.TemporaryDirectory() as tmp:
        paths = []
        for (name,data) in data_files.items():
            paths.append(os.path.join(tmp, name))
            with open(paths[-1], 'wb') as f:
                f.write(data)

        dat = os.path.join(tmp, "test.zip")
        pyminizip.compress_multiple(paths, [], dat, password, 9)

        with zipfile.ZipFile(dat, 'r') as zf:
            for (name, data) in data_files.items():
                dat_content = zf.read(name, password.encode())
                assert dat_content == data, f"{name}'s content from the zip did not match orig, zip content: {dat_content}"

if __name__ == '__main__':
    cli()

If this runs fine -- the password worked, and was successfully used to decompress/decrypt using the built-in library.

NOTE: the password needs to be bytes for the zipfile module, but for this (pyminizip) I believe the Py-C code (with the "Z#" format) can accept either bytes or str and will auto-encode str using UTF-8. This seems to work just fine, since my fork's trace statement shows the right password string was parsed and passed around correctly by the C-code.

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

No branches or pull requests

6 participants