Skip to content

Conversation

@VanshAgarwal24036
Copy link
Contributor

@VanshAgarwal24036 VanshAgarwal24036 commented Jan 20, 2026

This PR fixes a discrepancy between the C and pure Python implementations
of stat.filemode.

The pure Python implementation could misclassify arbitrary bit patterns
(e.g. 32767) as block devices. File type detection now correctly uses
(mode & S_IFMT) for file types, matching the C implementation.

A regression test is added to prevent this issue from recurring.

Fixes #144050

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a NEWS entry.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka merged commit fe62926 into python:main Jan 20, 2026
51 checks passed
@VanshAgarwal24036 VanshAgarwal24036 deleted the gh-144050 branch January 20, 2026 12:11
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 20, 2026
@miss-islington-app
Copy link

Thanks @VanshAgarwal24036 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @VanshAgarwal24036 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 20, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 20, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 20, 2026

GH-144073 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jan 20, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 20, 2026

GH-144074 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jan 20, 2026
serhiy-storchaka pushed a commit that referenced this pull request Jan 20, 2026
serhiy-storchaka pushed a commit that referenced this pull request Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discrepancy between stat.filemode's C and Python implementation

2 participants