libzip icon indicating copy to clipboard operation
libzip copied to clipboard

Add a different error code for truncated ZIPs

Open fdegros opened this issue 1 year ago • 1 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.

fdegros avatar Oct 06 '23 00:10 fdegros

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

dillof avatar Oct 06 '23 06:10 dillof

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

0-wiz-0 avatar Mar 15 '24 18:03 0-wiz-0

Thanks. I confirm this is implemented.

fdegros avatar Mar 20 '24 04:03 fdegros