Comments (10)
Nothing public. Of course zip_open
should fail, but mainly because miniz
function mz_zip_reader_read_central_dir
will fail.
So, if you need some workaround/shortcut, take a look into miniz.h
mz_zip_reader_read_central_dir
from zip.
Is there at least a "non" public function available, that checks the "End of central directory signature"?
from zip.
You can take a look into static function in miniz.h (mz_zip_reader_locate_header_sig)
:
https://github.com/kuba--/zip/blob/master/src/miniz.h#L5449
and how it's used in mz_zip_reader_read_central_dir
:
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)
from zip.
Thanks, I will take a look. Not sure if a separate function with the zip validity check can be extracted from the code
from zip.
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.
Alternatively some new function zip_check_open (zip_stream_check_open) could be added.
from zip.
Make sense, I think adding a new function which gonna set an error (like most of functions in our API) is the best approach.
from zip.
@abrasat I've pushed PR: https://github.com/kuba--/zip/pull/309
where I added:
int zip_noallocopen(struct zip_t **zip, const char *zipname, int level, char mode);
The function requires pre-allocated zip
and returns < 0 on error.
Right now, zip_open
is basically wrapper on top of zip_noallocopen
:
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.
from zip.
Thanks. Would be possible to forward the zip_noallocopen() error code to zip_open? Maybe add an new zip_open_extended function:
struct zip_t *zip_open_extended(const char *zipname, int level, char mode, int* errorCode) {
struct zip_t *zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t));
*errorCode = zip_noallocopen(&zip, zipname, level, mode);
if (*errorCode < 0) {
CLEANUP(zip);
return NULL;
}
return zip;
}
And please add also the same error check for the zip_stream_open() function
from zip.
Yep, I'll add zip_stream_noallocopen
in the similar way. But frankly speaking, having these noalloc
version I do not see the point to add yet another wrapper to the API. I hope it's not a lot of work to write own extended function (maybe with more error handling stuff)
from zip.
@abrasat - I closed the previous PR, because I realized it's not usable (you cannot preallocate anonymous struct).
So, I've just sent a new one (https://github.com/kuba--/zip/pull/310), which most likely works better for you.
PTAL.
from zip.
Related Issues (20)
- Bug when delete a file from a big size zip archive HOT 3
- Warnings HOT 1
- zip_create Why does create not support directory creation! HOT 3
- zip_extract The extracted file name is garbled and does not support Chinese name extraction HOT 1
- typedef conflict HOT 1
- zip_close error when opening zip archive in read mode HOT 5
- 64-bit Linux compatibility HOT 3
- Can CodeQL scans be enabled for this repository? HOT 1
- Bindings HOT 7
- Remove zip entries by index. HOT 2
- redefinition of 's_tdefl_num_probes' when `miniz.h` included in cpp HOT 1
- Find offset of a file in a zip file? HOT 6
- Issue when deleting files HOT 3
- Failed to compile with Android Studio NDK r26b HOT 1
- zip_entries_delete fails for in memory stream zip HOT 12
- Reading a portion of the file HOT 6
- Multiple issues with zip file HOT 7
- Code for supporting direct usage of file streams (FILE *) HOT 1
- miniz.h: surround function definitions with an #ifdef HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zip.