classification
Title: AssertRaises() causes core dump in handling recursion
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: out of date
Dependencies: Superseder: Cannot Recover From StackOverflow in 3.9 Tests
View: 45806
Assigned To: Mark.Shannon Nosy List: CharlesFengY, Mark.Shannon, iritkatriel, terry.reedy
Priority: normal Keywords:

Created on 2021-02-10 09:00 by CharlesFengY, last changed 2021-11-19 18:15 by lukasz.langa. This issue is now closed.

Messages (7)
msg386763 - (view) Author: Yang Feng (CharlesFengY) Date: 2021-02-10 09:00
Seeing the following program, in the second assertRaises(), function "test_invalid_adpcm_state()"  is recursively called. Then a fatal Python error shows up and the Python interpreter crashes. 

++++++++++++++++++++++++++++++++++++++
import unittest
import audioop

class TestAudioop(unittest.TestCase):
         pass

def test_invalid_adpcm_state():
         TestAudioop.assertRaises(TypeError, audioop.lin2adpcm, b'\x00', 1, 555)
         TestAudioop.assertRaises(test_invalid_adpcm_state(), audioop.adpcm2lin, b'\x00', 1, (0, (- 1)))

TestAudioop = TestAudioop()
test_invalid_adpcm_state()

+++++++++++++++++++++++++++++++++++++++

System Info: Ubuntu 16.04
Python Version:  Python 3.9.1
msg386775 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-10 11:55
Reproduced on master as well. Simplified script:

------------------------------------------
import unittest

def f():
    raise TypeError

class TestAudioop(unittest.TestCase):
    def test_invalid_adpcm_state(self):
        self.assertRaises(TypeError, f) 
        self.test_invalid_adpcm_state()

TestAudioop().test_invalid_adpcm_state()

------------------------------------------
msg386776 - (view) Author: Yang Feng (CharlesFengY) Date: 2021-02-10 12:27
Could you please tell me your secret method of getting the minimal script?
I will try to provide minimal ones in our following work.
msg386777 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-02-10 13:05
3.9 crashes.
On master, I'm not seeing a crash, just a RecursionError.


>>> import unittest
>>> 
>>> def f():
...     raise TypeError
... 
>>> class TestAudioop(unittest.TestCase):
...     def test_invalid_adpcm_state(self):
...         self.assertRaises(TypeError, f) 
...         self.test_invalid_adpcm_state()
... 
>>> TestAudioop().test_invalid_adpcm_state()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in test_invalid_adpcm_state
  File "<stdin>", line 4, in test_invalid_adpcm_state
  File "<stdin>", line 4, in test_invalid_adpcm_state
  [Previous line repeated 992 more times]
  File "<stdin>", line 3, in test_invalid_adpcm_state
  File "/home/mark/repos/cpython/Lib/unittest/case.py", line 730, in assertRaises
    context = _AssertRaisesContext(expected_exception, self)
  File "/home/mark/repos/cpython/Lib/unittest/case.py", line 168, in __init__
    _BaseTestCaseContext.__init__(self, test_case)
RecursionError: maximum recursion depth exceeded
msg386778 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-10 13:21
Yang - no secret really, just trial and error.
Mark - right I wasn't on master, sorry.
msg386779 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-02-10 13:25
I think this was fixed by https://github.com/python/cpython/pull/23568

The root cause seems to be the same as #42500, so I'm going to backport https://github.com/python/cpython/pull/23568 to 3.9
msg386910 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-13 05:11
#43186, #43187 also have recursive code that fails in 3.9 and recovers in 3.10.  Am closing them in favor of this.  Also suspect #43188, #43189, #43190 are duplicates.  Yang, recheck after Mark does the backport here.
History
Date User Action Args
2021-11-19 18:15:58lukasz.langasetstatus: open -> closed
superseder: Cannot Recover From StackOverflow in 3.9 Tests
resolution: out of date
stage: resolved
2021-02-13 05:11:37terry.reedysetmessages: + msg386910
2021-02-13 04:53:58terry.reedylinkissue43186 superseder
2021-02-13 04:50:57terry.reedysetmessages: - msg386896
2021-02-13 01:03:08terry.reedysetnosy: + terry.reedy
messages: + msg386896
2021-02-10 13:53:54Mark.Shannonsetassignee: Mark.Shannon
components: + Interpreter Core, - Library (Lib)
versions: - Python 3.10
2021-02-10 13:25:07Mark.Shannonsetmessages: + msg386779
2021-02-10 13:21:42iritkatrielsetmessages: + msg386778
2021-02-10 13:05:42Mark.Shannonsetmessages: + msg386777
2021-02-10 12:27:30CharlesFengYsetmessages: + msg386776
2021-02-10 11:56:09iritkatrielsetversions: + Python 3.10
2021-02-10 11:55:45iritkatrielsetnosy: + Mark.Shannon, iritkatriel
messages: + msg386775
2021-02-10 09:00:08CharlesFengYcreate