Message236699
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') |
|
Date |
User |
Action |
Args |
2015-02-26 19:21:59 | benhoyt | set | recipients:
+ benhoyt, vstinner, ezio.melotti, BreamoreBoy, python-dev, arnaudc, serhiy.storchaka |
2015-02-26 19:21:59 | benhoyt | set | messageid: <1424978519.31.0.514395329645.issue13617@psf.upfronthosting.co.za> |
2015-02-26 19:21:59 | benhoyt | link | issue13617 messages |
2015-02-26 19:21:58 | benhoyt | create | |
|