gh-86094 Add support for Unicode Path Extra Field in ZipFile#102566
Conversation
| # Unicode Path Extra Field | ||
| try: | ||
| up_version, up_name_crc = unpack('<BL', data[:5]) | ||
| if up_version == 1 and up_name_crc == self.orig_filename_crc: |
There was a problem hiding this comment.
Please check that it will be enough to calculate crc32 on the fly.
| if up_version == 1 and up_name_crc == self.orig_filename_crc: | |
| if up_version == 1 and up_name_crc == crc32(self.filename): |
There was a problem hiding this comment.
In my opinion, orig_filename_crc is necessary. filename in ZipInfo is the decoded value from ZipFile. But orig_filename_crc is the result of the CRC on filename before decoding. So it should be stored separately.
There was a problem hiding this comment.
Okay, how about passing the orig_filename_crc to _decodeExtra?
cpython/Lib/zipfile/__init__.py
Lines 1436 to 1463 in c75e016
Looks like _decodeExtra is only used at this moment. WDYT?
There was a problem hiding this comment.
That's a good idea! I will update. :)
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
| try: | ||
| up_version, up_name_crc = unpack('<BL', data[:5]) | ||
| if up_version == 1 and up_name_crc == self.orig_filename_crc: | ||
| up_unicode_name = data[5:].decode('utf-8') |
There was a problem hiding this comment.
According to the spec, please check the TSize if possible.
As UnicodeName is defined to be UTF-8, no UTF-8
byte order mark (BOM) is used. The length of this field is determined
by subtracting the size of the previous fields from TSize.
There was a problem hiding this comment.
The TSize is stored in the ln variable. I don't think we need to check it because we are storing data of the size defined by ln. If there is a problem, an exception would be thrown.
| except struct.error: | ||
| import warnings | ||
| warnings.warn("Corrupt unicode path extra field (0x7075)", stacklevel=2) | ||
| except UnicodeDecodeError: | ||
| import warnings | ||
| warnings.warn('Corrupt unicode path extra field (0x7075): invalid utf-8 bytes', stacklevel=2) |
There was a problem hiding this comment.
Please raise BadZipFile error to follow other conventions.
There was a problem hiding this comment.
I modified it in a way that throws an exception, but given that this is an extra field, wouldn't it be okay to ignore it and let the 'original' filename field be used if an exception is thrown?
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @corona10: please review the changes made to this pull request. |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @corona10: please review the changes made to this pull request. |
|
@yeojin-dev, thank you very much! |
Uh oh!
There was an error while loading. Please reload this page.