| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,9 +166,14 @@ def filemode(mode): | |||
| 166 | 166 | perm = [] | |
| 167 | 167 | for index, table in enumerate(_filemode_table): | |
| 168 | 168 | for bit, char in table: | |
| 169 | - if mode & bit == bit: | ||
| 170 | - perm.append(char) | ||
| 171 | - break | ||
| 169 | + if index == 0: | ||
| 170 | + if S_IFMT(mode) == bit: | ||
| 171 | + perm.append(char) | ||
| 172 | + break | ||
| 173 | + else: | ||
| 174 | + if mode & bit == bit: | ||
| 175 | + perm.append(char) | ||
| 176 | + break | ||
| 172 | 177 | else: | |
| 173 | 178 | if index == 0: | |
| 174 | 179 | # Unknown filetype | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,6 +163,11 @@ def test_mode(self): | |||
| 163 | 163 | self.statmod.S_IFREG) | |
| 164 | 164 | self.assertEqual(self.statmod.S_IMODE(st_mode), 0o666) | |
| 165 | 165 | ||
| 166 | + def test_filemode_does_not_misclassify_random_bits(self): | ||
| 167 | + # gh-144050 regression test | ||
| 168 | + self.assertEqual(self.statmod.filemode(0o77777)[0], "?") | ||
| 169 | + self.assertEqual(self.statmod.filemode(0o177777)[0], "?") | ||
| 170 | + | ||
| 166 | 171 | @os_helper.skip_unless_working_chmod | |
| 167 | 172 | def test_directory(self): | |
| 168 | 173 | os.mkdir(TESTFN) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix :func:`stat.filemode` in the pure-Python implementation to avoid misclassifying | ||
| 2 | + invalid mode values as block devices. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments