Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Discrepancy betweenstat.filemode's C and Python implementation #144050

Closed
Labels
3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@zahinwahab

Description

@zahinwahab

Bug report

Bug description:

We found a behavioral discrepancy between CPython and PyPy instat.filemode via fuzz testing. Upon further inspection, we observed this discrepancy attributes to the differences between CPython's C and Python implementation.

Environment

  • Python: 3.11.11
  • OS: Ubuntu 24.04.3 LTS

Observed Discrepancy

Incorrect file type detection instat.filemode(mode)

Reproduction

importstatprint(stat.filemode(32767))

Output

CPython (default):?rwsrwsrwt
Cpython (Python impl.):brwsrwsrwt

Root Cause

CPython's_stat.c determines the file type using(mode & S_IFMT) == S_IFBLK.
For 32767,(mode & S_IFMT) == 0o70000 does not match any known file type, so CPython correctly uses? as the file-type character.
Itspure-Python implementation instead checks:(mode & S_IFBLK) == S_IFBLK. This check incorrectly evaluatestrue for32767, causing Python implementation (which in turn affects PyPy) to misclassify the mode as ablock device, yielding the wrong prefixb.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp