gh-154490: Only keep permission bits of the mode argument in ZipFile.mkdir() - #154509
DevoidSloth wants to merge 2 commits into
Conversation
…pFile.mkdir() The file type bits of a caller-provided mode were previously mixed into the entry's external attributes, so a mode such as 0o107777 could mark the created entry as a socket instead of a directory. Sanitize the mode with & 0o7777, matching what stat.S_IMODE does, before combining it with S_IFDIR. Also spell the default mode as 0o777 instead of 511 in the signature and documentation, for consistency with os.mkdir().
|
The following commit authors need to sign the Contributor License Agreement: |
Documentation build overview
403 files changed ·
|
|
LGTM. But I would personally treat this as a bug fix and documentation improvement rather than a behavior change, which means that the detailed doc about behavior change across major versions is not needed and we can backport this to older maintaining Python versions. The compatibility issue it may introduce should be minimal since there should be no actual requirement to call Tracing the history, the issue gh-84353 and related PR had a more significant behavior change and actually introduced a regression, while it was still implemented as a bug fix and has been backported. |
ZipFile.mkdir()combines the caller-provided mode into the entry's external attributes without clearing the file type bits, so those bits can mark the created entry as something other than a directory:This PR sanitizes mode to its permission bits before combining it with
S_IFDIR, matching whatstat.S_IMODE()does, as suggested in the issue:It also spells the default mode as
0o777instead of511in the signature and documentation, for consistency withos.mkdir()(same value, clearer intent).Included:
test_mkdircoveringS_IFREGandS_IFLNKtype bits in mode, plus anextractall()round-trip.ZipFile.mkdir()with aversionchangednote.ZipFile.mkdir(mode)#154490