You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
zipfile library will raise uncaught oserror when reading length incorrect zip file #91087
I intentionally made some corrupted zip archive files for testing.
If some contents were removed from the archive instead of changing the bits. when trying to read such files, the zipfile will raise an uncaught OSError, instead of a badzipfile error as expected.
os is windows 10 x64 not sure if this also happens on the UNIX system or it's intended to be happen.
has this been fixed in newer versions of python? I'm getting the same error while trying to unpack a .bz2 archive on python 3.8.5, while python 3.11's zipfile returns BadZipFile exception, as expected.
Well, testzip() only catches BadZipFile. It does not catch the compression errors and OSError. This is not clearly documented, and would perhaps be worth to catch the compression errors. This OSError was caused by seek() with negative argument, which is a zipfile integrity error. Should it catch all OSErrors or only handle this particular case (offset can be checked before calling seek())?
You can easy reimplement this method in your code with larger flexibility. But it seems that some people found it useful.
Activity
ultimalium commentedon Mar 5, 2022
I intentionally made some corrupted zip archive files for testing.
If some contents were removed from the archive instead of changing the bits. when trying to read such files, the zipfile will raise an uncaught OSError, instead of a badzipfile error as expected.
os is windows 10 x64 not sure if this also happens on the UNIX system or it's intended to be happen.
code:
result:
OSError
[Errno 22] Invalid argument
File "test.py", line 20, in <module>
file = dmg.testzip()
MrSeemsGood commentedon Oct 25, 2023
has this been fixed in newer versions of python? I'm getting the same error while trying to unpack a .bz2 archive on python 3.8.5, while python 3.11's zipfile returns
BadZipFileexception, as expected.serhiy-storchaka commentedon May 18, 2026
Well,
testzip()only catchesBadZipFile. It does not catch the compression errors andOSError. This is not clearly documented, and would perhaps be worth to catch the compression errors. ThisOSErrorwas caused byseek()with negative argument, which is a zipfile integrity error. Should it catch allOSErrors or only handle this particular case (offset can be checked before callingseek())?You can easy reimplement this method in your code with larger flexibility. But it seems that some people found it useful.