gh-154490: Only keep permission bits of the mode argument in ZipFile.mkdir()#154509
Open
DevoidSloth wants to merge 1 commit into
Open
gh-154490: Only keep permission bits of the mode argument in ZipFile.mkdir()#154509DevoidSloth wants to merge 1 commit into
DevoidSloth wants to merge 1 commit 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().
Documentation build overview
|
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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