-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if file or stream is a valid "zip" archive #307
Comments
Nothing public. Of course |
Is there at least a "non" public function available, that checks the "End of central directory signature"? |
You can take a look into static function in and how it's used in if (!mz_zip_reader_locate_header_sig(
pZip, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG,
MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE, &cur_file_ofs))
return mz_zip_set_error(pZip, MZ_ZIP_FAILED_FINDING_CENTRAL_DIR);
/* Read and verify the end of central directory record. */
if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf,
MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) !=
MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) |
Thanks, I will take a look. Not sure if a separate function with the zip validity check can be extracted from the code |
Maybe it would be a good idea to add an "archive_corrupted" boolean flag in "struct zip_t". it would be set if zip_open() or zip_stream_open() fails, instead of returning a null zip_t pointer. The caller of the function could then check the "m_last_error" value in zip_t->mz_zip_archive. |
Make sense, I think adding a new function which gonna set an error (like most of functions in our API) is the best approach. |
@abrasat I've pushed PR: https://github.com/kuba--/zip/pull/309 int zip_noallocopen(struct zip_t **zip, const char *zipname, int level, char mode); The function requires pre-allocated Right now, struct zip_t *zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t));
if (zip_noallocopen(&zip, zipname, level, mode) < 0) {
CLEANUP(zip);
return NULL;
} Take a look, test it and let me know if it works for you. |
Thanks. Would be possible to forward the zip_noallocopen() error code to zip_open? Maybe add an new zip_open_extended function:
And please add also the same error check for the zip_stream_open() function |
Yep, I'll add |
@abrasat - I closed the previous PR, because I realized it's not usable (you cannot preallocate anonymous struct). |
Is there any function available, that allows to check if a file or stream is a valid zip archive?
The text was updated successfully, but these errors were encountered: