summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/memoryobject.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2026-02-07 19:56:35 +0300
committershadchin <[email protected]>2026-02-07 20:23:53 +0300
commit19d43a3e6fb4cb8ea11747d7d7bca7a3542fbb44 (patch)
tree0b1418938140a0b6470953bef6069454ffdf1bd0 /contrib/tools/python3/Objects/memoryobject.c
parent0879409bfc0891ab8103828a3bdbf0e960475fec (diff)
Update Python 3 to 3.13.12
commit_hash:71d3efea437a769b2b7910d196120bb02587046e
Diffstat (limited to 'contrib/tools/python3/Objects/memoryobject.c')
-rw-r--r--contrib/tools/python3/Objects/memoryobject.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/contrib/tools/python3/Objects/memoryobject.c b/contrib/tools/python3/Objects/memoryobject.c
index b1a58d6b40e..8dc53c9ccbb 100644
--- a/contrib/tools/python3/Objects/memoryobject.c
+++ b/contrib/tools/python3/Objects/memoryobject.c
@@ -2330,7 +2330,13 @@ memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep,
CHECK_RELEASED(self);
if (MV_C_CONTIGUOUS(self->flags)) {
- return _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep);
+ // Prevent 'self' from being freed if computing len(sep) mutates 'self'
+ // in _Py_strhex_with_sep().
+ // See: https://github.com/python/cpython/issues/143195.
+ self->exports++;
+ PyObject *ret = _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep);
+ self->exports--;
+ return ret;
}
bytes = PyBytes_FromStringAndSize(NULL, src->len);
@@ -3068,9 +3074,16 @@ memory_hash(PyObject *_self)
"memoryview: hashing is restricted to formats 'B', 'b' or 'c'");
return -1;
}
- if (view->obj != NULL && PyObject_Hash(view->obj) == -1) {
- /* Keep the original error message */
- return -1;
+ if (view->obj != NULL) {
+ // Prevent 'self' from being freed when computing the item's hash.
+ // See https://github.com/python/cpython/issues/142664.
+ self->exports++;
+ Py_hash_t h = PyObject_Hash(view->obj);
+ self->exports--;
+ if (h == -1) {
+ /* Keep the original error message */
+ return -1;
+ }
}
if (!MV_C_CONTIGUOUS(self->flags)) {