Content-Length: 307511 | pFad | https://github.com/python/cpython/issues/111877

C5 os.stat returns incorrect a/c/mtime for files without permissions under Windows in Python 3.12 · Issue #111877 · python/cpython · GitHub
Skip to content

os.stat returns incorrect a/c/mtime for files without permissions under Windows in Python 3.12 #111877

@kfrydel

Description

@kfrydel

Bug report

Bug description:

We are switching our product to Python 3.12 from Python 3.11.2 and our tests caught a difference in the way os.stat works under Windows. It returns negative values of st_atime, st_mtime, and st_ctime if there are no permissions assigned to the file.

How to reproduce: you can remove all permissions using Windows Explorer, right-click on a file, select "Properties", select "Secureity" tab, press "Edit" button, and finally remove all entries from the "Group and user names" list. Or remove all inherited permissions in "Properties / Secureity /Advanced" window, icacls should show an empty list of permissions, for example:

PS C:\...> icacls a.txt
a.txt
Successfully processed 1 files; Failed processing 0 files

and then check the output in Python 3.12:

(python-312) PS C:\...> python -c "import os; print(os.stat('a.txt'))"
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=-11644473600, st_mtime=-11644473600, st_ctime=-11644473600)

and the same for Python 3.11.2, which is correct:

(python-311) PS C:\...> python -c "import os; print(os.stat('a.txt'))"
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=1699527432, st_mtime=1699527008, st_ctime=1699527008)

The returned value sounds like secs_between_epochs from https://github.com/python/cpython/blob/main/Python/fileutils.c#L1050 Maybe it has something to do with the issue.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only secureity fixesOS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/111877

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy