summaryrefslogtreecommitdiffstats
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-12 22:28:31 (GMT)
committerGitHub <noreply@github.com>2018-01-12 22:28:31 (GMT)
commit5b76bdba071e7bbd9fda0b9b100d1506d95c04bd (patch)
tree6330db8f2ec3db059cdad53010c11bce85b388fc /Modules/_pickle.c
parentf3031b8a7ad71d3b6ed05da7f3041d9efbe773cf (diff)
downloadcpython-5b76bdba071e7bbd9fda0b9b100d1506d95c04bd.zip
cpython-5b76bdba071e7bbd9fda0b9b100d1506d95c04bd.tar.gz
cpython-5b76bdba071e7bbd9fda0b9b100d1506d95c04bd.tar.bz2
bpo-31993: Do not use memoryview when pickle large strings. (#5154)
PyMemoryView_FromMemory() created a memoryview referring to the internal data of the string. When the string is destroyed the memoryview become referring to a freed memory.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 5b3de4d..f8cbea1 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -2184,8 +2184,9 @@ _Pickler_write_bytes(PicklerObject *self,
/* Stream write the payload into the file without going through the
output buffer. */
if (payload == NULL) {
- payload = mem = PyMemoryView_FromMemory((char *) data, data_size,
- PyBUF_READ);
+ /* TODO: It would be better to use a memoryview with a linked
+ original string if this is possible. */
+ payload = mem = PyBytes_FromStringAndSize(data, data_size);
if (payload == NULL) {
return -1;
}