summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-03 01:38:37 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-03 01:38:37 (GMT)
commit0d3a003f241460e417f2108fecf990b7ce5d1449 (patch)
tree8f773e6a59bd4a5244f1025b870d294ccd4eb17e
parent135b6d8aa5a24b08170fd94114a80dfeb1ae963c (diff)
parent4a90ef03637fdc1bc63ee9be82fbf22cbaa68662 (diff)
downloadcpython-0d3a003f241460e417f2108fecf990b7ce5d1449.zip
cpython-0d3a003f241460e417f2108fecf990b7ce5d1449.tar.gz
cpython-0d3a003f241460e417f2108fecf990b7ce5d1449.tar.bz2
- Issue #14177: marshal.loads() now raises TypeError when given an unicode
string. Patch by Guilherme Gonçalves.
-rw-r--r--Lib/test/test_exceptions.py2
-rw-r--r--Lib/test/test_marshal.py7
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/marshal.c8
5 files changed, 15 insertions, 6 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 91d85ef..42536d3 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -38,7 +38,7 @@ class ExceptionTests(unittest.TestCase):
try:
try:
import marshal
- marshal.loads('')
+ marshal.loads(b'')
except EOFError:
pass
finally:
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index bd81a1a..83c348c 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -201,7 +201,7 @@ class BugsTestCase(unittest.TestCase):
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 @@ class BugsTestCase(unittest.TestCase):
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 --git a/Misc/ACKS b/Misc/ACKS
index 57b61107..17ea919 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -371,6 +371,7 @@ Yannick Gingras
Michael Goderbauer
Christoph Gohlke
Tim Golden
+Guilherme Gonçalves
Tiago Gonçalves
Chris Gonnerman
David Goodger
diff --git a/Misc/NEWS b/Misc/NEWS
index 1e16f96..7607e66 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -511,6 +511,9 @@ Core and Builtins
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 --git a/Python/marshal.c b/Python/marshal.c
index 77824d4..b94e8d8 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1384,7 +1384,7 @@ marshal_loads(PyObject *self, PyObject *args)
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 @@ marshal_loads(PyObject *self, PyObject *args)
}
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[] = {