Code Monkey home page Code Monkey logo

Comments (10)

kuba-- avatar kuba-- commented on June 10, 2024

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.

abrasat avatar abrasat commented on June 10, 2024

Is there at least a "non" public function available, that checks the "End of central directory signature"?

from zip.

kuba-- avatar kuba-- commented on June 10, 2024

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.

abrasat avatar abrasat commented on June 10, 2024

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.

abrasat avatar abrasat commented on June 10, 2024

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.

kuba-- avatar kuba-- commented on June 10, 2024

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.

kuba-- avatar kuba-- commented on June 10, 2024

@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.

abrasat avatar abrasat commented on June 10, 2024

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.

kuba-- avatar kuba-- commented on June 10, 2024

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.

kuba-- avatar kuba-- commented on June 10, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.