Skip to content

Adding encrypted raw entry fails after 2.4.0 #294

@vszakats

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;
}

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