FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-144050: Fix stat.filemode pure Python file type detection (GH-144059) by miss-islington · Pull Request #144074 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 8 additions & 3 deletions Lib/stat.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,14 @@ def filemode(mode):
perm = []
for index, table in enumerate(_filemode_table):
for bit, char in table:
if mode & bit == bit:
perm.append(char)
break
if index == 0:
if S_IFMT(mode) == bit:
perm.append(char)
break
else:
if mode & bit == bit:
perm.append(char)
break
else:
if index == 0:
# Unknown filetype
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_stat.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def test_mode(self):
self.statmod.S_IFREG)
self.assertEqual(self.statmod.S_IMODE(st_mode), 0o666)

def test_filemode_does_not_misclassify_random_bits(self):
# gh-144050 regression test
self.assertEqual(self.statmod.filemode(0o77777)[0], "?")
self.assertEqual(self.statmod.filemode(0o177777)[0], "?")

@os_helper.skip_unless_working_chmod
def test_directory(self):
os.mkdir(TESTFN)
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`stat.filemode` in the pure-Python implementation to avoid misclassifying
invalid mode values as block devices.
Loading

Back | FazBrowse Home | New Git URL