Author Michael.Felt
Recipients Michael.Felt, jkloth, vstinner
Date 2018-10-02.17:36:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <5dd4323d-8d13-d540-f3d0-fad3c1b20829@felt.demon.nl>
In-reply-to <1538469361.99.0.545547206417.issue34711@psf.upfronthosting.co.za>
Content
On 10/2/2018 10:36 AM, STINNER Victor wrote:
> STINNER Victor <vstinner@redhat.com> added the comment:
>
> Jeremy Kloth: "This is also an issue on Windows when the target path resides within a junction, paths outside of a junction respond (err, fail) as expected."
> https://developercommunity.visualstudio.com/content/problem/272379/createfile-non-error-on-filename-with-trailing-bac.html
> I don't know the behavior on Windows. I tried to create a file name "a\" (U+0061, U+005C): I get an OSError "invalid argument" (error 22).
>
> I confirm that in a junction point, I am able to:
>
> * open an existing file with an additional trailing antislash (U+005C): the extra character is simply ignored and I am able to open the file
>
> * create a new file with an additional trailing antislash (U+005C): the filename is created without the trailing antislash
>
> On the PR, I wrote:
>
>
>> There are much more functions which "open a file". Open Python/fileutils.c for a few mores. What about os.open()? What about all other functions which accept a filename and then call a third party library which calls open() directly?
> Ok, let me give some examples of function which directly open a file:
>
> * fileutils.c: _Py_open(), _Py_open_noraise(), _Py_wfopen(), _Py_fopen(), _Py_fopen_obj()
> * os.open()
> * _io.FileIO, _pyio.FileIO (use os.open())
>
> Ok... But there are other functions to access files... stat()/fstat() functions:
>
> * fileutils.c: _Py_fstat_noraise(), _Py_fstat(), _Py_stat()
> * Modules/getpath.c: _Py_wstat()
> * os.stat(), os.lstat(), os.fstat()
>
> To start to have a better ideas of how many functions accept filenames, open also Lib/shutil.py. shutil.copyfile() uses os.stat(), but then it uses os.symlink() and open()... So what about os.symlink()?
>
> Ok, here I only listen a *few* examples of functions which are "controlled" by Python. But there are *many* wrappers to 3rd party libraries which accept a filename. Examples:
>
> * _ssl.SSLContext.load_cert_chain()
> * sqlite3.connect()
> * etc.
>
> Where is the limit? How many functions must be patched in Python? How do we patch OpenSSL and SQLite libraries?
>
> Python is designed as a thin wrapper to the operating system. IMHO Python must not validate the filename itself.
>
> --
>
>> Going back to issue17234 - there has been a test to check that a URL with a trailing slash reports 404 status.
> IMHO you must fix a single place: the SimpleHTTPServer, not all code handling the filesytem.
What I did not know: do you want the test to be okay as is, or set
SkipIf(condition) for operating systems that accept filename/ as a
filename when it is not directory.

IMHO: the "statement" of the test is that the name "test/" MUST be
rejected in all cases.

        # check for trailing "/" which should return 404. See Issue17324
        response = self.request(self.base_url + '/test/')
        self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)

Title <http://docs.python.org/devguide/triaging.html#title>:
SimpleHTTPServer serves files even if the URL has a trailing slash

I can assume the test was adjusted to catch the 404 return code, and let
that pass on OS that will not open .../test.txt and .../text.txt/ as the
same object - while AIX (and windows does).

As to your comment about "other" things that can happen - the message in
the test implies that Python only wants "filenames" that are opened
without a slash. I guess there is not a PEP on this, so anyones guess is
likely to be wrong for someone.

In short, this PR took the road where Python says .../filename/ is wrong
- per the comment in the test.

So, what should be done: code in HTTPServer that checks for trailing
slash and the test can be left ASIS, or modify the test to skip this one
aspect on an OS that is known to accept ".../filename/" as a valid filename?

I am not "core" enough to make this choice. I can attempt to code any
decision made by "python-dev" aka core-devs.
> Same remark for AIX and Windows junctions.
>

> I suggest to reject this issue.
per above, I would rather not reject the issue - I would still like to
see the test fixed. But need help on what should actually be modified.
Test, Module, or internals.
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue34711>
> _______________________________________
>
History
Date User Action Args
2018-10-02 17:36:12Michael.Feltsetrecipients: + Michael.Felt, vstinner, jkloth
2018-10-02 17:36:12Michael.Feltlinkissue34711 messages
2018-10-02 17:36:11Michael.Feltcreate