[issue33721] os.path.exists() ought to return False if pathname contains NUL

2018-05-31 Thread pacujo


New submission from pacujo :

os.path.exists() returns True or False for all imaginable string arguments 
except for one that contains NUL ("\0") (Linux). This behavior is not 
documented in the library. Moreover, it can easily lead to accidents if  an 
externally supplied pathname were to contain a NUL because most test suites 
would not try to cover such a pathname.

I propose os.path.exists() should return False even in this case.

--
components: Library (Lib)
messages: 318334
nosy: pacujo
priority: normal
severity: normal
status: open
title: os.path.exists() ought to return False if pathname contains NUL
type: behavior
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue33721>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33721] os.path.exists() ought to return False if pathname contains NUL

2018-06-14 Thread pacujo


pacujo  added the comment:

Eryk Sun:
> I only meant that, as an honest error, it has to be ValueError. I didn't
> think about raising a fake OSError.
>
> Note that I didn't say the ValueError shouldn't be ignored by
> os.path.exists (et al). In the spirit of the current function, it
> probably should be ignored. For example, it returns False for paths that
> exist but are inaccessible.

For the original complaint of mine, catching ValueError would work. I
must say, though, that Steven's arguments for raising a fake OSError are
very convincing.

Steven D'Aprano:
> Jython does this:
> 
> >>> import os
> >>> os.path.exists('/tmp/foo\0bar')
> False
> >>> os.stat('/tmp/foo\0bar')
> Traceback (most recent call last):
>   File "", line 1, in 
> OSError: [Errno 2] No such file or directory: '/tmp/foo\x00bar'
> 
> 
> As far as I am concerned, raising ValueError is simply a bug. The
> documentation for the os module clearly states:
> 
> All functions in this module raise OSError in the case of
> invalid or inaccessible file names and paths, or other
> arguments that have the correct type, but are not accepted
> by the operating system.

Now the question is not anymore if and how CPython should be fixed but
if and how Jython should be fixed.

IMO, Jython is doing the right thing. If that is not true, then Jython
must be declared buggy.

> Maybe it could raise an InvalidFilename subclass of OSError. This
> could even handle some actual OS errors such as POSIX ENAMETOOLONG and
> Windows ERROR_INVALID_NAME, ERROR_BAD_PATHNAME, and
> ERROR_FILENAME_EXCED_RANGE.

Maybe. You'll still need OSError.errno to hold a true error value.

Marko

--

___
Python tracker 
<https://bugs.python.org/issue33721>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com