nih-at/libzip

Add a different error code for truncated ZIPs

fdegros opened this issue · 3 comments

Description

When libzip tries to open an incomplete (truncated) ZIP archive, it fails with the error code ZIP_ER_NOZIP "Not a zip archive".

Solution

Would it be possible to distinguish the two situations by returning different error codes?

  • The file doesn't look like a ZIP archive at all.
    In this case ZIP_ER_NOZIP "Not a zip archive" is appropriate.
  • The file looks like the beginning of a (truncated but otherwise valid) ZIP archive.
    In this case, a different error code (eg ZIP_ER_TRUNCATED "Truncated zip archive") would be preferred.

Additional context

Around 2% of all the ZIP archives that are opened by the ChromeOS Files App fail because of the ZIP_ER_NOZIP error. This percentage is stable over time, and it looks quite high. I am wondering if this is due to truncated ZIPs, or if there is another issue at play.

dillof commented

This sounds like a good idea and shouldn't be hard to implement.

I've just implemented this - let us know how this changed your percentage of invalid zip archives!
Thanks for the suggestion.

Thanks. I confirm this is implemented.