This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benhoyt
Recipients BreamoreBoy, arnaudc, benhoyt, ezio.melotti, python-dev, serhiy.storchaka, vstinner
Date 2015-02-26.19:21:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424978519.31.0.514395329645.issue13617@psf.upfronthosting.co.za>
In-reply-to
Content
Note that this (or a very similar issue) also affects os.listdir() on Windows: os.listdir(bytes_path_with_nul) raises ValueError as expected, but os.listdir(unicode_path_with_nul) does not. Test case:

>>> import os
>>> os.mkdir('foo')
>>> os.listdir(b'foo\x00zzz')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: listdir: embedded null character in path
>>> os.listdir('foo\x00zzz')
[]

However, this is not the case on Linux, as there both calls raise an appropriate ValueError.

This needs to be fixed in posixmodule.c's path_converter() function.

I'm in the middle of implementing PEP 471 (os.scandir), so don't want to create a proper patch right now, but the fix is to add these lines in posixmodule.c path_converter() after the if (length > 32767) {...} block:

        if ((size_t)length != wcslen(wide)) {
            FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
            Py_DECREF(unicode);
            return 0;
        }

We should also add test to test_os.py like the following:

    def test_listdir_nul_in_path(self):
        self.assertRaises(ValueError, os.listdir, 'y\x00z')
        self.assertRaises(ValueError, os.listdir, b'y\x00z')
History
Date User Action Args
2015-02-26 19:21:59benhoytsetrecipients: + benhoyt, vstinner, ezio.melotti, BreamoreBoy, python-dev, arnaudc, serhiy.storchaka
2015-02-26 19:21:59benhoytsetmessageid: <1424978519.31.0.514395329645.issue13617@psf.upfronthosting.co.za>
2015-02-26 19:21:59benhoytlinkissue13617 messages
2015-02-26 19:21:58benhoytcreate