Repository navigation
Closed
Labels
Description
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
vszakats commentedon Aug 7, 2018
More precisely it worked till commit 7f6f08a. The likely commit causing this regression is the one following it: 298126a.
Clean up reading and writing of raw entries. #294
nmoinvaz commentedon Aug 8, 2018
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.
vszakats commentedon Aug 8, 2018
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.With the example code in the original post here,
7zasays:ERROR: E_FAILwhen trying to extracttestcopy.zipwith the correct password.Fixes to reading raw encrypted entries. #294
Use uint8_t for raw parameter. #294
Change order of parameters for consistency. #294
nmoinvaz commentedon Aug 9, 2018
That should solve the problem.
vszakats commentedon Aug 9, 2018
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.
vszakats commentedon Aug 10, 2018
Live test (DEFLATE+AES-encrypted raw + non-raw entries) has been successful! (as of commit 9eb113d)
nmoinvaz commentedon Aug 10, 2018
Awesome thanks!