Ben Hoyt added the comment: 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') ---------- nosy: +benhoyt _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13617> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com