Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ee1b24cc
Commit
ee1b24cc
authored
Nov 25, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__. Original patch by Antoine Pitrou.
parent
282e831a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
Lib/test/test_descr.py
Lib/test/test_descr.py
+22
-1
Misc/NEWS
Misc/NEWS
+3
-0
Objects/typeobject.c
Objects/typeobject.c
+5
-1
No files found.
Lib/test/test_descr.py
View file @
ee1b24cc
...
...
@@ -4763,6 +4763,26 @@ class PTypesLongInitTest(unittest.TestCase):
type
.
mro
(
tuple
)
class
PicklingTests
(
unittest
.
TestCase
):
def
test_issue24097
(
self
):
# Slot name is freed inside __getattr__ and is later used.
class
S
(
str
):
# Not interned
pass
class
A
(
object
):
__slotnames__
=
[
S
(
'spam'
)]
def
__getattr__
(
self
,
attr
):
if
attr
==
'spam'
:
A
.
__slotnames__
[:]
=
[
S
(
'spam'
)]
return
42
else
:
raise
AttributeError
import
copy_reg
expected
=
(
copy_reg
.
__newobj__
,
(
A
,),
({},
{
'spam'
:
42
}),
None
,
None
)
self
.
assertEqual
(
A
().
__reduce__
(
2
),
expected
)
def
test_main
():
deprecations
=
[(
r'complex divmod\
(
\), // and % are deprecated$'
,
DeprecationWarning
)]
...
...
@@ -4774,7 +4794,8 @@ def test_main():
with
test_support
.
check_warnings
(
*
deprecations
):
# Run all local test cases, with PTypesLongInitTest first.
test_support
.
run_unittest
(
PTypesLongInitTest
,
OperatorsTest
,
ClassPropertiesAndMethods
,
DictProxyTests
)
ClassPropertiesAndMethods
,
DictProxyTests
,
PicklingTests
)
if
__name__
==
"__main__"
:
test_main
()
Misc/NEWS
View file @
ee1b24cc
...
...
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
Core and Builtins
-----------------
- Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__.
- Issue #24731: Fixed crash on converting objects with special methods
__str__, __trunc__, and __float__ returning instances of subclasses of
str, long, and float to subclasses of str, long, and float correspondingly.
...
...
Objects/typeobject.c
View file @
ee1b24cc
...
...
@@ -3269,12 +3269,16 @@ reduce_2(PyObject *obj)
for
(
i
=
0
;
i
<
PyList_GET_SIZE
(
names
);
i
++
)
{
PyObject
*
name
,
*
value
;
name
=
PyList_GET_ITEM
(
names
,
i
);
Py_INCREF
(
name
);
value
=
PyObject_GetAttr
(
obj
,
name
);
if
(
value
==
NULL
)
if
(
value
==
NULL
)
{
Py_DECREF
(
name
);
PyErr_Clear
();
}
else
{
int
err
=
PyDict_SetItem
(
slots
,
name
,
value
);
Py_DECREF
(
name
);
Py_DECREF
(
value
);
if
(
err
)
goto
end
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment