fancycode / pylzma

Python bindings for the LZMA library

Home Page:http://www.joachim-bauch.de/projects/pylzma/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Most recent commit fails unittest on Windows

KenV99 opened this issue · comments

commented

Using windows 7 x64 and Python 32bit 2.7:
and commit: cc2bfaf

During unittest test_7zfiles.py.Test7ipFiles.test_encrypted_names_password
line 164 "archive = Archive7z(fp, password='secret')" fails without raising an exception in:
py7zlib.ArchiveFile._read_7z_aes256_sha256
at line 698 "result = cipher.decrypt(input)"

Using debugger this line fails without raising an exception and execution halts.

What type of debugger do you use, Python- or C-level? This line calls into the C extension to perform the AES decryption, which then for some reason fails for you.
Decryption is also done in the test_encrypted_password testcase - does that work for you, or does it also crash (you can comment the crashing test_encrypted_names_password to skip it)?

Unfortunately I don't have a way to reproduce this yet.

commented

I am using pydevd as a debugger. I don't know C well enough to do a debug build. Sorry.

Four unittests all fail at the same line (698 in py7zlib.py) as listed above:
test_encrypted_password
test_encrypted_wong_password
test_encrypted_names_password
test_encrypted_names_wong_password

I am not sure if this has anything to do with it (I doubt it), but during the build I get a command line warning D9025L overriding '/MD' with '/MT' for each c file.

I probably found the issue. Could you please check 2f48f6b to see if that fixes your problem?

commented

The build now fails:

pylzma_aes.c
src/pylzma/pylzma_aes.c(58) : error C2143: syntax error : missing ';' before 'type'
src/pylzma/pylzma_aes.c(59) : error C2065: 'offset' : undeclared identifier
src/pylzma/pylzma_aes.c(60) : error C2065: 'offset' : undeclared identifier
src/pylzma/pylzma_aes.c(120) : error C2143: syntax error : missing ';' before 'type'
src/pylzma/pylzma_aes.c(121) : error C2065: 'offset' : undeclared identifier
src/pylzma/pylzma_aes.c(122) : error C2065: 'offset' : undeclared identifier
src/pylzma/pylzma_aes.c(144) : error C2061: syntax error : identifier 'aesdecrypt_methods'
src/pylzma/pylzma_aes.c(144) : error C2059: syntax error : ';'
src/pylzma/pylzma_aes.c(144) : error C3409: empty attribute block is not allowed
src/pylzma/pylzma_aes.c(144) : error C2513: '/global/ ' : no variable declared before '='
src/pylzma/pylzma_aes.c(178) : error C2065: 'aesdecrypt_methods' : undeclared identifier
src/pylzma/pylzma_aes.c(178) : error C2099: initializer is not a constant
src/pylzma/pylzma_aes.c(186) : warning C4047: 'initializing' : 'Py_ssize_t' differs in levels of indirection from 'initproc'
error: command 'C:\Users\Ken User\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe' failed with exit status
2

But thanks for your efforts.

Oh right, the MS compiler is a bit picky about variables in C code... Should hopefully work now.

commented

Builds and passes unittests now. Thanks!
However, I'm still getting an error trying to decompress a password protected file created by a recent version of 7z. Same as documented:#26

My real question is: Is it possible to create a compatible, password protected 7z file using this library with Python?

Hmm, the test_encrypted_names_XXX unittests use a file that was created using the same command you described in #26. Could you please provide a (small) failing sample file together with the password, so I can fix the issue and add it to the test suite?

commented

I tried and found that the errors that I am experiencing seem to have to do with problems surrounding an EOF error. This could be specific to windows.

Here is some code that I am using to try to troubleshoot:

http://pastebin.com/sHg3UaRr

This code demonstrates that the file contents that py7zlib reads in is not the same as what was written to the 7z file. When I run it at line 90 the string that is read in is not as the same as what was written - it is truncated. Then the pickle fails to load with an EOF error.

An example 7z files is here:

https://www.dropbox.com/s/xdhlxfg7g6563p7/info7.7z?dl=0

This may seem to be unrelated to my original statements above, but I believe it is the same issue. I just restructured the code so that the error is more obvious.

Thanks, that example helped. For some cases, encrypted data was not truncated correctly.

commented

Thanks very much. All working as expected now.

commented

I'm not sure if it's bad etiquette to raise a related issue in a closed issue, so please forgive me if it is.
If I change the command line in the previous code in pastebin to include the -mhe switch to encrypt headers, I get an 'invalid block data error' from Archive7z.__init__() in py7zlib.py.

In what may be a side note, in class Header.__init__() in the line self.properties = ArchiveProperties(file), ArchiveProperties is not defined in py7zlib.py.

Thanks again for all of your help.