New submission from Arnon Yaari <wiggi...@gmail.com>:

The C implementation of the "stat" module on Python 3 (_stat) is using the type 
"mode_t" for file modes, which differs between operating systems. This type can 
be defined as either "unsigned short" (for example, in macOS, or the definition 
added specifically for Windows in _stat.c) or "unsigned long" (Linux and other 
Unix systems such as AIX).
This means that the "stat" module may only work with file modes that come from 
the same system that Python was compiled for.
It is sometimes desirable to work with file modes on remote systems (for 
example, when using the "fabric" module to handle remote files - 
https://github.com/fabric/fabric/blob/1.10/fabric/sftp.py#L42).
With the pure-python "stat" module on Python 2.7, using macros such as 
"stat.S_ISDIR" with any value used to work (even values that exceed "unsigned 
short" on macOS, for example) but with the C implementation this can result in 
an exception on systems with an "unsigned short" mode_t:

    >>> stat.S_ISDIR(0o240755)
    OverflowError: mode out of range

I encountered this exception when trying to "put" files from a macOS system to 
an AIX system with "fabric" (0o240755 is the st_mode found for "/" on AIX).

For uniform handling of file modes, modes should be handled as unsigned long 
instead of the system-defined "mode_t".

----------
components: Library (Lib)
messages: 362499
nosy: wiggin15
priority: normal
severity: normal
status: open
title: stat.S_ISXXX can raise OverflowError for remote file modes
type: behavior
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39729>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to