Repository navigation
Description
We have the following workflow to read an entry from file
// Pseudocode
int32_t err;
err = mz_zip_goto_entry(zip_handle, offset);
err = mz_zip_entry_get_info(zip_handle, ...);
auto read_bytes = mz_zip_entry_read(zip_handle, ...);
uint32_t expectedCRC32;
int64_t expectedCompressedSize;
int64_t expectedUncompressedSize;
err = mz_zip_entry_read_close(zip_handle, &expectedCRC32, &expectedCompressedSize, &expectedUncompressedSize);We noticed that mz_zip_entry_read_close manipulates the stream if non-NULL args are passed
Lines 2104 to 2110 in 55db144
| /* Seek to end of compressed stream since we might have over-read during compression */ | |
| if (err == MZ_OK) { | |
| err = mz_stream_seek(zip->stream, | |
| MZ_ZIP_SIZE_LD_ITEM + (int64_t)zip->local_file_info.filename_size + | |
| (int64_t)zip->local_file_info.extrafield_size + total_in, | |
| MZ_SEEK_CUR); | |
| } |
However, the comment only speaks of compression which is not the case for a read-only archive.
Hence, we observed that the stream manipulation in mz_zip_entry_read_close lead to corrupt streams for reads of subsequent enries (mz_zip_entry_read_header fails on the MZ_ZIP_MAGIC_CENTRALHEADER check).
Lines 233 to 234 in 55db144
| else if ((!local) && (magic != MZ_ZIP_MAGIC_CENTRALHEADER)) | |
| err = MZ_FORMAT_ERROR; |
As a workaround we simply call mz_zip_entry_close instead which solves the issue as now mz_zip_entry_read_close is called with NULL args.
Is it a file issue, an application issue or library issue? Thank you!
Activity
nmoinvaz commentedon Mar 5, 2025
That comment should say decompression not compression.
nmoinvaz commentedon Mar 5, 2025
I'm not sure what the particulars of your zip are. Is it using data descriptors? Can you attach it?
thbeu commentedon Mar 6, 2025
Thanks for replying. Please find the zip archive attached. It is the archive file Aufschluesse.zip within the attached file: Issue840.zip
pmqs commentedon Mar 9, 2025
Here is a readout on the structure of Issue840.zip. Nothing looks out of the ordinary
Similarly,
unzipthionks all is okthbeu commentedon Mar 9, 2025
Actually, it's the ZIP file Aufschluesse. 10BC8 zip within the provided ZIP archive which caused the issue for us.
pmqs commentedon Mar 9, 2025
Sorry, misread the message.
unzipthinksAufschluesse.zipis ok.Here is what the metatdata looks like. Only thing that stands out is the entries are streamed. Ignore the messages about the unexpected
Extra Field 'Extended Timestamp'.nmoinvaz commentedon Mar 10, 2025
Zips in zips are not compatible with data descriptors, you will have to disable data descriptors.
thbeu commentedon Mar 10, 2025
Sorry for the confusion: The actual file is Aufschluesse.zip. I zipped it additionally to avoid any accidentally repacking when uploading to GitHub. So again: Unpack Aufschluesse.zip from Issue840.zip and handle Aufschluesse.zip via minizip-ng. Hence, it is not about zip in zip. It's all about file Aufschluesse.zip.
thbeu commentedon Mar 10, 2025
OK. Might that be the cause of the observed issue?
nmoinvaz commentedon Mar 10, 2025
Yes turn off data descriptors and it should work.
thbeu commentedon Mar 11, 2025
It's not in our hand how the ZIP file is created. We need to handle both ZIP files with
MZ_ZIP_FLAG_DATA_DESCRIPTORset and not set.To me it looks like a library issue since
mz_zip_entry_read_closemust not be called with non-NULL args on data descriptor entries.zlib-ng#840 Restore stream position after reading data descriptor in …
zlib-ng#840 Restore stream position after reading data descriptor in …