classification
Title: Segmentation fault in running compile() with large expression size.
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Segmentation fault in running ast.literal_eval() with large expression size.
View: 42712
Assigned To: Nosy List: stestagg, xxm
Priority: normal Keywords:

Created on 2020-12-22 10:19 by xxm, last changed 2020-12-26 01:41 by terry.reedy. This issue is now closed.

Messages (2)
msg383579 - (view) Author: Xinmeng Xia (xxm) Date: 2020-12-22 10:19
Calling function compile() with large size can cause a segmentation fault in Python 3.7 -3.10. Please check the following two examples. The example 1 works as expected, while the second one triggers segmentation fault on Python 3.7,3.8,3.9,3.10. The primary difference between these two examples lay on the value of "n".   


Example 1:
=========================================
mylist = []
n = 100000
print(compile("mylist"+"+mylist"*n,'','single'))
==========================================

The actual output: Recursion Error on Python 3.5-3.10 (as expected)




Example 2:
=========================================
mylist = []
n = 1000000
print(compile("mylist"+"+mylist"*n,'','single'))
===================================

The actual output: Recursive Error on Python 3.5, 3.6 (as expected),  segmentation fault on Python 3.7, 3.8, 3.9, 3.10 (not as expected)




My system information:

>> python3.10 -V
Python 3.10.0a2

>> python3.9 -V
Python 3.9.0rc1

>> python3.8 -V
Python 3.8.0

>> python3.7 -V
Python 3.7.3

>> python3.6 -V
Python 3.6.12

>> uname -v
#73~16.04.1-Ubuntu
msg383606 - (view) Author: Steve Stagg (stestagg) Date: 2020-12-22 19:25
As with the other ones, 
PR: https://github.com/python/cpython/pull/23744 stops this from segfaulting.  It does however raise a RecursionError:

RecursionError: maximum recursion depth exceeded during compilation

As per https://bugs.python.org/issue42609#msg382910, Serhiy implies that the new recursion error is probably expected and acceptable.
History
Date User Action Args
2020-12-26 01:41:26terry.reedysetstatus: open -> closed
superseder: Segmentation fault in running ast.literal_eval() with large expression size.
resolution: duplicate
stage: resolved
2020-12-22 19:25:15stestaggsetnosy: + stestagg
messages: + msg383606
2020-12-22 10:19:47xxmcreate