Closed
Labels
Description
When I only open and close a compressed package, I find that its size is larger and corrupted.
For Example:
zipFile zf;
char *filePath = "xxx";
zf = zipOpen(filePath, 1);
int err = zipClose(zf,NULL);
I took a look at the code and changed it to solve the problem, but I don't know if the change will affect other parts.
Change the following(mz_zip.c):
if ((mode & MZ_OPEN_MODE_READ) || (mode & MZ_OPEN_MODE_APPEND))
{
err = mz_zip_read_cd(zip);
if ((mode & MZ_OPEN_MODE_CREATE) == 0)
{
//err = mz_zip_read_cd(zip);
if (err != MZ_OK)
{
mz_zip_print("Zip - Error detected reading cd (%"PRId32")", err);
if (zip->recover && mz_zip_recover_cd(zip) == MZ_OK)
err = MZ_OK;
}
}
if ((err == MZ_OK) && (mode & MZ_OPEN_MODE_APPEND))
{
if (zip->cd_size > 0)
{
/* Store central directory in memory */
err = mz_stream_seek(zip->stream, zip->cd_offset, MZ_SEEK_SET);
if (err == MZ_OK)
err = mz_stream_copy(zip->cd_mem_stream, zip->stream, (int32_t)zip->cd_size);
if (err == MZ_OK)
err = mz_stream_seek(zip->stream, zip->cd_offset, MZ_SEEK_SET);
}
else
{
/* If no central directory, append new zip to end of file */
err = mz_stream_seek(zip->stream, 0, MZ_SEEK_END);
}
if (zip->disk_number_with_cd > 0)
{
/* Move to last disk to begin appending */
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, zip->disk_number_with_cd - 1);
}
}
else
{
zip->cd_start_pos = zip->cd_offset;
}
}
I put 'err = mz_zip_read_cd(zip)' in front
I also found a problem when I deleted some of the comments in a compressed package with comments and found that its size did not change, But I use winRAR modified, compressed package size will be smaller.Is there any way to reconcile the two?
Activity
nmoinvaz commentedon Apr 19, 2019
If you change that, it will not work for some open modes. If you attach the zip file you are having problems with and the repo steps and code then I can try and track it down.
zhouyang9967 commentedon Apr 22, 2019
cert-v1.1.1.1-c426f4aca002d697898ceae925a9f85f.zip
cert-v1.1.1.1-c426f4aca002d697898ceae925a9f85f.zip
The first is to open the closed zip file, and the second is corrupted,The code performs only the open and close operations as in the example
zhouyang9967 commentedon Apr 22, 2019
The above one is modified comment, this one is not modified
example.zip
example.zip
nmoinvaz commentedon Apr 22, 2019
In both instances, your zip files do not contain a central directory. You can open it in recovery mode using the new api function mz_zip_set_recover and that will create a central directory if set before opening. I can make a slight change that will not try and save the central directory header if the central directory size is zero. It would allow you to at least open and close without corruption. But if you are going to make modifications you will need a central directory. This is list on the Wiki page under Limitations.
Do not write central directory header if central directory is 0 bytes. …