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

LZMA encryption fails with 2.7.0 #334

Closed
vszakats opened this issue Oct 31, 2018 · 6 comments
Closed

LZMA encryption fails with 2.7.0 #334

vszakats opened this issue Oct 31, 2018 · 6 comments
Labels
encryption Encryption/decryption issue fixed Issue or bug has been fixed lzma XZ compression format

Comments

@vszakats
Copy link
Contributor

$ curl -LO https://github.com/nmoinvaz/minizip/archive/2.7.0.tar.gz
$ tar -xvf 2.7.0.tar.gz
$ cd minizip-2.7.0
$ cmake .
$ make
$ clang test-crypt.c  -I. -L. -lminizip -lbz2 -lz

test-crypt.c:

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "mz.h"
#include "mz_zip.h"
#include "mz_compat.h"

int main(void)
{
    zip_fileinfo zfi;
    const unsigned char content[] = "abcdefghijklmnopqrstuvvvwwwxxx";
    zipFile hZip;

    // create .zip
    printf("zcreat: %p\n", (void *)(hZip = zipOpen2_64("test.zip", APPEND_STATUS_CREATE, NULL, NULL)));
    memset(&zfi, 0, sizeof(zfi));
    printf("zaddfi: %d\n", zipOpenNewFileInZip4_64(hZip, "test.txt", &zfi, NULL, 0, NULL, 0, NULL,
                                                   MZ_COMPRESS_METHOD_LZMA, 6, 0,
                                                   -MAX_WBITS, DEF_MEM_LEVEL, 0,
                                                   "password", 0x4c72ad0a /* crc of 'content' */,
                                                   0, 0, 0));
    printf("zwrite: %d\n", zipWriteInFileInZip(hZip, content, sizeof(content)));
    printf("zfclos: %d\n", zipCloseFileInZip(hZip));
    printf("zclose: %d\n", zipClose(hZip, NULL));

    return 0;
}

actual output:

zcreat: 0x7fbdf2c02cc0
zaddfi: -102
zwrite: -1
zfclos: -102
zclose: 0

expected (and actual result with 2.6.0):

zcreat: 0x7fd15ac02cc0
zaddfi: 0
zwrite: 0
zfclos: 0
zclose: 0

(Tested on macOS 10.14)

@vszakats vszakats changed the title Encryption fails with 2.7.0 LZMA encryption fails with 2.7.0 Oct 31, 2018
@vszakats
Copy link
Contributor Author

vszakats commented Nov 1, 2018

Used crypto module is mz_crypt_brg.c.

@nmoinvaz
Copy link
Member

nmoinvaz commented Nov 1, 2018

I am very surprised by this. I worked on Travis CI to test all the possible cases.

@nmoinvaz
Copy link
Member

nmoinvaz commented Nov 1, 2018

I would at some point like to make a native version for macOS of the mz_crypt file.

nmoinvaz added a commit that referenced this issue Nov 1, 2018
@nmoinvaz
Copy link
Member

nmoinvaz commented Nov 1, 2018

I think I got it. Thanks.

@nmoinvaz nmoinvaz closed this as completed Nov 1, 2018
@vszakats
Copy link
Contributor Author

vszakats commented Nov 1, 2018

Thanks! Though in latest dev, the above sample no longer compiles, with these errors:

test-crypt.c:22:53: error: use of undeclared identifier 'MAX_WBITS'
                                                   -MAX_WBITS, DEF_MEM_LEVEL, 0,
                                                    ^
test-crypt.c:22:64: error: use of undeclared identifier 'DEF_MEM_LEVEL'
                                                   -MAX_WBITS, DEF_MEM_LEVEL, 0,
                                                               ^
2 errors generated.

@vszakats
Copy link
Contributor Author

vszakats commented Nov 1, 2018

Ref this comment: f79ec42#commitcomment-31132281

@nmoinvaz nmoinvaz added 2.0 encryption Encryption/decryption issue fixed Issue or bug has been fixed lzma XZ compression format labels Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
encryption Encryption/decryption issue fixed Issue or bug has been fixed lzma XZ compression format
Projects
None yet
Development

No branches or pull requests

2 participants