(original) (raw)
changeset: 75375:e67b3a9bd2dc parent: 75373:8ec51b2e57c2 parent: 75374:4966907d3661 user: Antoine Pitrou solipsis@pitrou.net date: Sat Mar 03 02:38:37 2012 +0100 files: Lib/test/test_exceptions.py Lib/test/test_marshal.py Misc/ACKS Misc/NEWS Python/marshal.c description: - Issue #14177: marshal.loads() now raises TypeError when given an unicode string. Patch by Guilherme Gonçalves. diff -r 8ec51b2e57c2 -r e67b3a9bd2dc Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Sat Mar 03 01:32:57 2012 +0100 +++ b/Lib/test/test_exceptions.py Sat Mar 03 02:38:37 2012 +0100 @@ -38,7 +38,7 @@ try: try: import marshal - marshal.loads('') + marshal.loads(b'') except EOFError: pass finally: diff -r 8ec51b2e57c2 -r e67b3a9bd2dc Lib/test/test_marshal.py --- a/Lib/test/test_marshal.py Sat Mar 03 01:32:57 2012 +0100 +++ b/Lib/test/test_marshal.py Sat Mar 03 02:38:37 2012 +0100 @@ -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 8ec51b2e57c2 -r e67b3a9bd2dc Misc/ACKS --- a/Misc/ACKS Sat Mar 03 01:32:57 2012 +0100 +++ b/Misc/ACKS Sat Mar 03 02:38:37 2012 +0100 @@ -371,6 +371,7 @@ Michael Goderbauer Christoph Gohlke Tim Golden +Guilherme Gonçalves Tiago Gonçalves Chris Gonnerman David Goodger diff -r 8ec51b2e57c2 -r e67b3a9bd2dc Misc/NEWS --- a/Misc/NEWS Sat Mar 03 01:32:57 2012 +0100 +++ b/Misc/NEWS Sat Mar 03 02:38:37 2012 +0100 @@ -511,6 +511,9 @@ Library ------- +- Issue #14177: marshal.loads() now raises TypeError when given an unicode + string. Patch by Guilherme Gonçalves. + - Issue #13550: Remove the debug machinery from the threading module: remove verbose arguments from all threading classes and functions. diff -r 8ec51b2e57c2 -r e67b3a9bd2dc Python/marshal.c --- a/Python/marshal.c Sat Mar 03 01:32:57 2012 +0100 +++ b/Python/marshal.c Sat Mar 03 02:38:37 2012 +0100 @@ -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; @@ -1400,10 +1400,10 @@ } PyDoc_STRVAR(loads_doc, -"loads(string)\n\ +"loads(bytes)\n\ \n\ -Convert the string to a value. If no valid value is found, raise\n\ -EOFError, ValueError or TypeError. Extra characters in the string are\n\ +Convert the bytes object to a value. If no valid value is found, raise\n\ +EOFError, ValueError or TypeError. Extra characters in the input are\n\ ignored."); static PyMethodDef marshal_methods[] = { /solipsis@pitrou.net