diff -r 67d9595a833c Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Fri Mar 02 22:54:03 2012 +0100 +++ b/Lib/test/test_exceptions.py Fri Mar 02 20:38:27 2012 -0300 @@ -38,7 +38,7 @@ try: try: import marshal - marshal.loads('') + marshal.loads(b'') except EOFError: pass finally: diff -r 67d9595a833c Lib/test/test_marshal.py --- a/Lib/test/test_marshal.py Fri Mar 02 22:54:03 2012 +0100 +++ b/Lib/test/test_marshal.py Fri Mar 02 20:38:27 2012 -0300 @@ -201,7 +201,7 @@ pass def test_loads_recursion(self): - s = 'c' + ('X' * 4*4) + '{' * 2**20 + s = b'c' + (b'X' * 4*4) + b'{' * 2**20 self.assertRaises(ValueError, marshal.loads, s) def test_recursion_limit(self): @@ -274,6 +274,11 @@ finally: support.unlink(support.TESTFN) + def test_loads_reject_unicode_strings(self): + # Issue #14177: marshal.loads() should not accept unicode strings + unicode_string = 'T' + self.assertRaises(TypeError, marshal.loads, unicode_string) + def test_main(): support.run_unittest(IntTestCase, diff -r 67d9595a833c Python/marshal.c --- a/Python/marshal.c Fri Mar 02 22:54:03 2012 +0100 +++ b/Python/marshal.c Fri Mar 02 20:38:27 2012 -0300 @@ -1370,7 +1370,7 @@ "dumps(value[, version])\n\ \n\ Return the string that would be written to a file by dump(value, file).\n\ -The value must be a supported type. Raise a ValueError exception if\n\ +The value must support the buffer interface. Raise a TypeError exception if\n\ value has (or contains an object that has) an unsupported type.\n\ \n\ The version argument indicates the data format that dumps should use."); @@ -1384,7 +1384,7 @@ char *s; Py_ssize_t n; PyObject* result; - if (!PyArg_ParseTuple(args, "s*:loads", &p)) + if (!PyArg_ParseTuple(args, "y*:loads", &p)) return NULL; s = p.buf; n = p.len;