gh-121021: zipfile: Support for extended_mtime attribute#121020
gh-121021: zipfile: Support for extended_mtime attribute#121020Akasurde wants to merge 1 commit intopython:mainfrom
Conversation
|
Info-Zip's The python implementation populates the ZipInfo data from the central directory which, according to Zip-Info's description, may only contain the modified time. Python only reads the local header (with all three fields potentially present) when opening the archived entry for reading/ decompression and that read is primarily used for some sanity checks before decompression rather than extracting additional extra fields for further use. You could rework this PR to focus on extracting the modified time when present if that's still useful for you? Another potential issue is Raising a BadZipFile in the case A test showing reading the field successfully would be useful. You could look to the tests for the utf filename extra fields for inspiration: https://github.com/python/cpython/blob/main/Lib/test/test_zipfile/test_core.py#L1837 |
|
@danifus Thanks a lot for the review. I updated the PR with your suggestions. |
danifus
left a comment
There was a problem hiding this comment.
Nice changes. Test cases look good too
| if ln < 5: | ||
| raise BadZipFile('Empty extended timestamp extra field (0x5455)') from None | ||
| if flags & 0x1 and ln >= 5: | ||
| self.extended_mtime = int.from_bytes(extra[5:9], "little") |
There was a problem hiding this comment.
This should be a signed int:
int.from_bytes(b'\x00\x00\x00\x80', byteorder='little', signed=True)
-2147483648
are you able to add a test showing the behaviour beyond the 2038 problem date (which would also be the test showing it is a signed field)?
A call to struct's unpack would also be consistent with the other fields (and a little faster) and allow you to catch the case where not enough bytes for a long were supplied:
unpack('<l', extra[5:9])
|
|
||
| elif tp == 0x5455: | ||
| flags = extra[4] | ||
| if ln < 5: |
There was a problem hiding this comment.
ln can be less than 5 and still be valid. The flags in the local header and central header should always be the same and may indicate that any combination of the 3 times are present (even though the central header can only store the mtime). So it is possible that the atime and ctime flags are set but not the mtime and the central header would only have the flags byte and no time data.
The info-zip description says the mtime 'must' be present in the central header if the mtime flag is set but I'd settle for a warning.
You could move this check above the flags = extra[4] line and change it to catch the potential (corrupt) case where ln == 0. If ln == 0 it is either going to raise an IndexError or return the first byte from the next extra field.
danifus
left a comment
There was a problem hiding this comment.
Thanks for adding those last suggestions. These are the last ones I have. Nice work!
danifus
left a comment
There was a problem hiding this comment.
Windows tests were failing on the 2038 test so here's some suggestions about that.
Last changes for sure this time :p
zipinfo now supports attributes like extended_atime, extended_ctime, extended_mtime Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
|
@danifus Anything else required over here? Thanks. |
|
No more changes from me :) Nice work LGTM |
|
@danifus Do I need to do anything to get this merged? Thanks. |
|
You'll need to get a review from a core developer and then they can help get it merged (I also have a few waiting :p ). Have a read of the experts index https://devguide.python.org/core-developers/experts/index.html - there maybe someone in there that could review it for you. |
|
@serhiy-storchaka, @Yhg1s, @gpshead Could you please review this PR? Thanks in advance. |
|
This PR is stale because it has been open for 30 days with no activity. |
zipinfo now supports attribute - extended_mtime
fixes: #121021
📚 Documentation preview 📚: https://cpython-previews--121020.org.readthedocs.build/