8000 Adding encrypted raw entry fails after 2.4.0 · Issue #294 · zlib-ng/minizip-ng · GitHub
[go: up one dir, main page]

Skip to content

Adding encrypted raw entry fails after 2.4.0 #294

Closed

Description

@vszakats

zipOpenNewFileInZip4_64() returns -102 when built with 2.4.0. With 2.3.9, it works fine:

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

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

int main(void)
{
    int iResult;
    zip_fileinfo zfi;
    const unsigned char content[] = "abcdefghijklmnopqrstuvvvwwwxxx";
    zipFile hZip;
    unzFile hUnzip;
    unz_file_info64 ufi;
    void * buffer;
    int iRead;

    // 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));

    // create another .zip by using raw data of the above
    // (= without recompressing)
    printf("zcreat: %p\n", (void *)(hZip = zipOpen2_64("testcopy.zip", APPEND_STATUS_CREATE, NULL, NULL)));
    printf("uopen : %p\n", (void *)(hUnzip = unzOpen2_64("test.zip", NULL)));

    printf("ufinfo: %d\n", unzGetCurrentFileInfo64(hUnzip, &ufi, NULL, 0, NULL, 0, NULL, 0));
    printf("ufopen: %d\n", unzOpenCurrentFile3(hUnzip, NULL, NULL, 1 /* raw! */, NULL));

    memset(&zfi, 0, sizeof(zfi));
    zfi.dosDate     = ufi.dosDate;
    zfi.internal_fa = ufi.internal_fa;
    zfi.external_fa = ufi.external_fa;
    printf("zaddfi: %d\n", zipOpenNewFileInZip4_64(hZip, "test.txt", &zfi, NULL, 0, NULL, 0, NULL,
                                                   ufi.compression_method, 6, 1 /* raw! */,
                                                   -MAX_WBITS, DEF_MEM_LEVEL, 0,
                                                   NULL, 0,
                                                   0, ( 1 << 0 ) /* encrypted */, 0));
    buffer = malloc(1024);
    printf("uread : %d\n", iRead = unzReadCurrentFile( hUnzip, buffer, 1024));
    printf("zwrite: %d\n", zipWriteInFileInZip(hZip, buffer, iRead));
    free(buffer);
    printf("zfclos: %d\n", zipCloseFileInZipRaw(hZip, ufi.uncompressed_size, ufi.crc));
    printf("ufclos: %d\n", unzCloseCurrentFile(hUnzip));
    printf("uclose: %d\n", unzClose(hUnzip));
    printf("zclose: %d\n", zipClose(hZip, NULL));

    return 0;
}

Activity

  1. vszakats commented on Aug 7, 2018

    @vszakats
    ContributorAuthor

    More precisely it worked till commit 7f6f08a. The likely commit causing this regression is the one following it: 298126a.

  2. nmoinvaz commented on Aug 8, 2018

    @nmoinvaz
    Member

    Take a look at what I did with the latest check-in. Let me know if it fixes all the use cases u have for reading/writing raw entries. I reluctantly added raw parameter to write entry function but I know it is the right thing to do.

  3. vszakats commented on Aug 8, 2018

    @vszakats
    ContributorAuthor

    After the update, creating a raw/encrypted entry does work, but the resulting output cannot be extracted.

    Entry size (for copied item file_3.bin) seems to be corrupted in this private test. On a closer look into file, the AES header and the raw content are both missing from the entry created in raw/encrypted mode.

    $ unzip -lv testcp.zip
    [...]
     Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
    --------  ------  ------- ---- ---------- ----- --------  ----
       14480  Unk:099    4437  69% 07-19-2018 12:23 05bf7428  file_1.bin
      157984  Unk:099   41683  74% 08-08-2018 10:11 615f1cfe  file_2.bin
        1801  Unk:09918446744073709551606 -30524931% 06-18-2018 13:45 504a2381  file_3.bin
           0  Unk:099      16   0% 07-20-2018 18:56 00000000  file_9.bin
    --------          -------  ---                            -------
      174265            46126  74%                            4 files
    

    With the example code in the original post here, 7za says: ERROR: E_FAIL when trying to extract testcopy.zip with the correct password.

  4. nmoinvaz commented on Aug 9, 2018

    @nmoinvaz
    Member

    That should solve the problem.

  5. vszakats commented on Aug 9, 2018

    @vszakats
    ContributorAuthor

    Thanks a lot for your fixes! As far as my isolated/minimal tests go, everything is fine now! I'm going to test it live later today/evening.

  6. vszakats commented on Aug 10, 2018

    @vszakats
    ContributorAuthor

    Live test (DEFLATE+AES-encrypted raw + non-raw entries) has been successful! (as of commit 9eb113d)

  7. nmoinvaz commented on Aug 10, 2018

    @nmoinvaz
    Member

    Awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedIssue or bug has been fixedrawRaw file storage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0