8000 Problems with mz_zip_writer_open() function · Issue #377 · zlib-ng/minizip-ng · GitHub
[go: up one dir, main page]

Skip to content

Problems with mz_zip_writer_open() function #377

Closed

Description

@stepankonrad

My intention is to create a ZIP file on disk and stream in-memory files into the archive, possibly several GB large.

With the following minimum working example

void* zipWriter = nullptr;
void* zipStream = nullptr;

mz_stream_os_create(&zipStream);
mz_stream_os_open(zipStream, "archive.zip", MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);

mz_zip_writer_create(&zipWriter);
mz_zip_writer_open(zipWriter, zipStream);

mz_zip_file info = {};
info.filename = "testfilename";
info.filename_size = 13;
info.compression_method = MZ_COMPRESS_METHOD_STORE;

mz_zip_writer_add_buffer(zipWriter, "filecontent", 12, &info);

mz_zip_writer_close(zipWriter);
mz_stream_os_close(zipStream);

I am getting the following verbose debug output:

Zip - Open
Zip - Entry - Write open - testfilename (level 9 raw 0)
Zip - Entry - Write - 12 (max 12)
Zip - Entry - Read Close
Zip - Entry - Crc failed (actual 0x52d869b7 expected 0x00000000)

I also tests precalculating the CRC and storing it in info.crc which didn't work as well.
The "Read Close" in the log made me a bit suspicious.
When changing the following function in mz_zip_rw.c from

int32_t mz_zip_writer_open(void *handle, void *stream)
{
    return mz_zip_writer_open_int(handle, stream, 0);
}

to

int32_t mz_zip_writer_open(void *handle, void *stream)
{
    return mz_zip_writer_open_int(handle, stream, MZ_OPEN_MODE_WRITE);
}

then I get the following output:

Zip - Open
Zip - Entry - Write open - testfilename (level 9 raw 0)
Zip - Entry - Write - 12 (max 12)
Zip - Entry - Write Close (crc 0x52d869b7 cs -1 ucs -1 )
Zip - Entry - Write cd (ucs 12 cs 12 crc 0x52d869b7)
Zip - Close
Zip - Write cd (disk 0 entries 1 offset 82 size 58)

and the archive is created successfully.

Do I use the wrong version/way/flavour of the API? Why is the mz_zip_writer_open() function opening the archive in mode == 0? Is this simply a bug?

Do you have a recommendation which API calls I could replace to make it work?

Activity

  1. nmoinvaz commented on Mar 30, 2019

    @nmoinvaz
    Member

    This does appear to be a bug. I have fixed it in the dev branch. Thank you for reporting it!

  2. added
    fixedIssue or bug has been fixed
    and removed on Apr 19, 2019
  3. added a commit that references this issue on Aug 8, 2023
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 fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0