Skip to content

Segmentation fault with compile #113297

Closed
@shadchin

Description

@shadchin

Crash report

What happened?

Minimal reproducible example

tests.py

def mocks(self, search_rv=None, mock_internal_search=False):
    with mock.patch.object(
        TestResourceController, "_search" if mock_internal_search else "search", return_value=search_rv
    ) as mock_search, mock.patch.object(TestResourceController, "_count") as mock_count, mock.patch.object(
        TestResourceController, "_before_create"
    ) as mock_before_create, mock.patch.object(
        TestResourceController, "_create"
    ) as mock_create, mock.patch.object(
        TestResourceController, "_after_create"
    ) as mock_after_create, mock.patch.object(
        TestResourceController, "_before_update"
    ) as mock_before_update, mock.patch.object(
        TestResourceController, "_update"
    ) as mock_update, mock.patch.object(
        TestResourceController, "_after_update"
    ) as mock_after_update, mock.patch.object(
        TestResourceController, "_before_delete"
    ) as mock_before_delete, mock.patch.object(
        TestResourceController, "_delete"
    ) as mock_delete, mock.patch.object(
        TestResourceController, "_after_delete"
    ) as mock_after_delete, mock.patch.object(
        TestResourceController, "validate"
    ) as mock_validate, mock.patch.object(
        TestSourceManager, "search", side_effect=self.mock_source_search_func()
    ) as mock_source_search, mock.patch.object(
        TestSourceManager, "before_create"
    ) as mock_source_before_create, mock.patch.object(
        TestSourceManager, "after_create"
    ) as mock_source_after_create, mock.patch.object(
        TestSourceManager, "before_update"
    ) as mock_source_before_update, mock.patch.object(
        TestSourceManager, "after_update"
    ) as mock_source_after_update, mock.patch.object(
        TestSourceManager, "before_delete"
    ) as mock_source_before_delete, mock.patch.object(
        TestSourceManager, "after_delete"
    ) as mock_source_after_delete, mock.patch.object(
        TestSourceManager2, "search", side_effect=self.mock_source_search_func()
    ) as mock_source2_search:
        yield 1

crash.py

with open("tests.py") as f:
    source = f.read()

compile(source, "tests.py", "exec")

Segmentation fault

shadchin@i113735019 ~ % python3.12 crash.py
zsh: segmentation fault  python3.12 crash.py
Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   Python                        	       0x1047dc148 _PyCfg_OptimizeCodeUnit + 348
1   Python                        	       0x1047c1eb0 optimize_and_assemble + 252
2   Python                        	       0x1047c9298 compiler_function + 584
3   Python                        	       0x1047c2a30 compiler_body + 208
4   Python                        	       0x1047c0c70 compiler_codegen + 148
5   Python                        	       0x1047c02d8 _PyAST_Compile + 44
6   Python                        	       0x10480c81c Py_CompileStringObject + 112
7   Python                        	       0x1047a881c builtin_compile + 508
8   Python                        	       0x104711e34 cfunction_vectorcall_FASTCALL_KEYWORDS + 92
9   Python                        	       0x1047b7820 _PyEval_EvalFrameDefault + 43368
10  Python                        	       0x1047acc48 PyEval_EvalCode + 184
11  Python                        	       0x10480e4d0 run_eval_code_obj + 88
12  Python                        	       0x10480c6a8 run_mod + 132
13  Python                        	       0x10480bbb0 pyrun_file + 148
14  Python                        	       0x10480af8c _PyRun_SimpleFileObject + 288
15  Python                        	       0x10480ac64 _PyRun_AnyFileObject + 232
16  Python                        	       0x10482fa14 pymain_run_file_obj + 220
17  Python                        	       0x10482f674 pymain_run_file + 72
18  Python                        	       0x10482ee0c Py_RunMain + 860
19  Python                        	       0x10482ef50 Py_BytesMain + 40
20  dyld                          	       0x195463f28 start + 2236


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x00000001042e4500   x1: 0x00000000000000b0   x2: 0x0000000000000000   x3: 0x000000000000003f
    x4: 0x0000000000000020   x5: 0x000000000000003e   x6: 0x0000000000000000   x7: 0x000000000000001c
    x8: 0x000000000000000c   x9: 0x00000000042d26f0  x10: 0x0000000000000660  x11: 0x00000001048cf440
   x12: 0x0000000000000028  x13: 0x0000000000000001  x14: 0x0000000104aff8c0  x15: 0x0000000000000001
   x16: 0x0000000000000008  x17: 0x0000600000acc090  x18: 0x0000000000000000  x19: 0x0000000142648960
   x20: 0x00000001426380d0  x21: 0x000000016bdb2ad0  x22: 0x0000000000000000  x23: 0x0208805008000001
   x24: 0x00000001042d26a0  x25: 0x00000001426488b0  x26: 0x0000000104183470  x27: 0x0000000000000000
   x28: 0x00000001042d26f0   fp: 0x000000016bdb2ac0   lr: 0x00000001047dc314
    sp: 0x000000016bdb29a0   pc: 0x00000001047dc148 cpsr: 0x20001000
   far: 0x0000000125816bf0  esr: 0x92000006 (Data Abort) byte read Translation fault

CPython versions tested on:

3.12

Operating systems tested on:

Linux, macOS

Output from running 'python -VV' on the command line:

Python 3.12.1 (main, Dec 8 2023, 18:57:37) [Clang 14.0.3 (clang-1403.0.22.14.1)]

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixestype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions