Skip to content

gh-84419: Fix the execute permissions in os.stat() on Windows - #155392

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-84419-stat-trailing-spaces
Open

gh-84419: Fix the execute permissions in os.stat() on Windows#155392
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-84419-stat-trailing-spaces

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Windows strips trailing dots and spaces from the last component of the path, so os.stat('spam.bat ') returns the information about the same file as os.stat('spam.bat'), but the execute permissions were not set in st_mode, because the extension '.bat ' did not match '.bat':

>>> oct(os.stat('spam.bat').st_mode)
'0o100777'
>>> oct(os.stat('spam.bat ').st_mode)
'0o100666'

Trailing dots and spaces are now ignored, unless the path starts with the \\?\ prefix, which disables the path normalization.

This does not fix the difference between os.stat() and os.scandir() for such paths, which needs a separate change.

Windows strips trailing dots and spaces from the last component of the path,
so os.stat('spam.bat ') opened the same file as os.stat('spam.bat'), but did
not set the execute permissions in st_mode, because the extension did not
match.  They are now ignored, unless the \\?\ prefix disables the path
normalization.
@serhiy-storchaka
serhiy-storchaka requested a review from zooba August 8, 2026 17:39
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes OS-windows stdlib Standard Library Python modules in the Lib/ directory type-bug An unexpected behavior, bug, or error and removed type-bug An unexpected behavior, bug, or error stdlib Standard Library Python modules in the Lib/ directory OS-windows labels Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant