New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The zipfile module does not check files' CRCs, including in ZipFile.testzip #51716
Comments
The zipfile module does not calculate the CRC of files in a zipfile as It would be useful if ZipExtFile could check the CRC once it had read Steps to reproduce: I can provide a patch in a couple of days if that's useful. |
Douglas could you please provide a patch. |
Patch looks good to me. |
Actually, there are two places where the internal buffer is trimmed from consumed data: self._readbuffer = self._readbuffer[self._offset:] + data
self._offset = 0 At this point, it seems self._crc_offset should also be reset to zero, otherwise some data will be forgotten on the next read() call. |
This is an updated patch with fixed (hopefully) CRC logic in the face of buffering, and additional tests. |
Nir, want to take a look? |
I think patch may be simplified. Instead of keeping track of CRC offset, invoke it directly on the 'data' variable being added to _readbuffer. Also the call to _update_crc() before the return from read1() looks redundant. Finally, is it possible to determine end of file if length of 'data' (computed for crc) is 0? |
Ok, here is a new patch with a simpler logic. I've also added tests with a deflated zipfile entry with a bad CRC (in addition to the one with a stored zipfile entry).
I'm not sure I understand the question. |
But you answered my question with code :) self._file_size is now unused and may be removed. |
Ah, indeed. I've committed an updated patch in r83959 (py3k), r83962 (3.1) and r83961 (2.7). Thank you! |
At Barry's request, here is a patch for potential backport to 2.6. |
After chatting with __ap__ on irc, i'm going to reject this patch for 2.6.6. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: