diff -r 51ac5f06dd04 Lib/test/test_os.py --- a/Lib/test/test_os.py Tue Jul 24 03:45:39 2012 -0700 +++ b/Lib/test/test_os.py Wed Jul 25 11:35:41 2012 +0900 @@ -1047,6 +1047,9 @@ def test_chdir(self): self.assertRaises(WindowsError, os.chdir, support.TESTFN) + def test_chdir_invalid_filename(self): + self.assertRaises(WindowsError, os.chdir, b'\xe7w\xf0') + def test_mkdir(self): f = open(support.TESTFN, "w") try: diff -r 51ac5f06dd04 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Jul 24 03:45:39 2012 -0700 +++ b/Objects/unicodeobject.c Wed Jul 25 11:35:41 2012 +0900 @@ -3694,7 +3694,7 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size) { #ifdef HAVE_MBCS - return PyUnicode_DecodeMBCS(s, size, NULL); + return PyUnicode_DecodeMBCS(s, size, "surrogateescape"); #elif defined(__APPLE__) return PyUnicode_DecodeUTF8Stateful(s, size, "surrogateescape", NULL); #else