[issue32137] Stack overflow in repr of deeply nested dicts

2018-02-02 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2018-02-02 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset b7a2c17be8411bc4c7a2babdc650074c14204aa8 by Serhiy Storchaka in 
branch '2.7':
[2.7] bpo-32137: The repr of deeply nested dict now raises a RuntimeError 
(GH-4570) (#5493)
https://github.com/python/cpython/commit/b7a2c17be8411bc4c7a2babdc650074c14204aa8


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2018-02-02 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +5326

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2018-02-02 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

The issue seems somewhat contrived but the fix looks fine to me.

--
assignee: rhettinger -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2018-02-01 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 688b6dec4e8847a154ef27257069291175764794 by Serhiy Storchaka 
(Miss Islington (bot)) in branch '3.6':
bpo-32137: The repr of deeply nested dict now raises a RecursionError (GH-4570) 
(GH-4689)
https://github.com/python/cpython/commit/688b6dec4e8847a154ef27257069291175764794


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-24 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Could you please take a look at PR 4689 and PR 4812 Raymond? I remember you had 
objections against similar changes and I have small hesitates. What way of 
solving this issue in maintained releases do you prefer?

--
assignee:  -> rhettinger
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-12 Thread Ben North

Change by Ben North :


--
pull_requests: +4716

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-12 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

PR 4812 is an alternate fix for 3.6. It doesn't touch reprs of other types.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-12 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +4707

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-03 Thread Roundup Robot

Change by Roundup Robot :


--
pull_requests: +4602

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-12-03 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 1fb72d2ad243c965d4432b4e93884064001a2607 by Serhiy Storchaka in 
branch 'master':
bpo-32137: The repr of deeply nested dict now raises a RecursionError (#4570)
https://github.com/python/cpython/commit/1fb72d2ad243c965d4432b4e93884064001a2607


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-11-28 Thread STINNER Victor

Change by STINNER Victor :


--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-11-26 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +4498
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32137] Stack overflow in repr of deeply nested dicts

2017-11-26 Thread Serhiy Storchaka

New submission from Serhiy Storchaka :

repr() of deeply nested dicts and dictviews can cause a stack overflow.

>>> x = {}
>>> for i in range(10):
... x = {1: x}
... 
>>> repr(x)
Segmentation fault

>>> x = {}
>>> for i in range(10):
... x = {1: x}
... 
>>> repr(x.values())
Segmentation fault

repr() of virtually all other deeply nested collections are guarded by using 
Py_EnterRecursiveCall().

>>> x = ()
>>> for i in range(10):
... x = (x,)
... 
>>> repr(x)
Traceback (most recent call last):
  File "", line 1, in 
RecursionError: maximum recursion depth exceeded while getting the repr of a 
tuple

>>> x = []
>>> for i in range(10):
... x = [x]
... 
>>> repr(x)
Traceback (most recent call last):
  File "", line 1, in 
RecursionError: maximum recursion depth exceeded while getting the repr of a 
list

>>> x = frozenset()
>>> for i in range(10):
... x = frozenset({x})
... 
>>> repr(x)
Traceback (most recent call last):
  File "", line 1, in 
RecursionError: maximum recursion depth exceeded while getting the repr of a 
list

>>> from collections import OrderedDict
>>> x = {}
>>> for i in range(10):
... x = OrderedDict({1: x})
... 
>>> repr(x)
Traceback (most recent call last):
  File "", line 1, in 
RecursionError: maximum recursion depth exceeded while getting the repr of a 
list

>>> from collections import deque
>>> x = deque()
>>> for i in range(10):
... x = deque([x])
... 
>>> repr(x)
Traceback (most recent call last):
  File "", line 1, in 
RecursionError: maximum recursion depth exceeded while getting the repr of a 
list

But the case of infinite recursion already is handled:

>>> x = {}
>>> x[1] = x
>>> repr(x)
'{1: {...}}'

Only finite but very deep recursion causes a crash.

The one possible solution -- add Py_EnterRecursiveCall() in the implementation 
of dict.__repr__(), like it already is added in list.__repr__() and 
tuple.__repr__().

The more general solution -- add Py_EnterRecursiveCall() in PyObject_Repr(). In 
any case it is called before calling PyObject_Repr() for every item in the repr 
of most collections except dict. And it is already added in PyObject_Str(). 
Therefore adding it will not add much overhead, but can handle more corner 
cases.

See also issue18533 and issue25240.

--
components: Interpreter Core
messages: 306997
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Stack overflow in repr of deeply nested dicts
type: crash
versions: Python 2.7, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com