python / python/cpython

`MemoryError` during parse can escalate to `SystemError` and abort on small input

未关闭
#150,001 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core topic-parser type-crash
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Crash report

What happened?
string = (
    b'(*h(((h(h(h(' +
    b'[' * 35 +
    b'*h(' +
    b'[' * 38 +
    b'**h(' +
    b'[' * 31 +
    b'(' * 4 +
    b'~' * 20 +
    b'F{' +
    b'[' * 27 +
    b'**h(' +
    b'[' * 31 +
    b'(' * 4 +
    b'~' * 23 +
    b'F{F"{F"{F"{F"{F"{F"{F"{FF""{{F"{""{F"{F{{F"{F"{F"\\}'
)

compile(string, "<input>", "single")

Gives me:

Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
MemoryError: Parser stack overflowed - Python source too complex to parse

The above exception was the direct cause of the following exception:

SystemError: <class 'SyntaxWarning'> returned a result with an exception set

Current thread 0x00007efd1b8e8780 [python] (most recent call first):
  File "/tmp/repro.py", line 19 in <module>
Aborted                    (core dumped) ./python /tmp/repro.py

Found by OSS-Fuzz.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

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

No response

Linked PRs
  • gh-150067

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在 CPython main 上运行提供的 compile() 复现程序,并将其 MemoryError/SystemError 失败与报告的致命中止进行比较。阅读涉及的 parser 和 SyntaxWarning 处理,然后审查链接的 PR gh-150067。当输入不再中止解释器,也不再将 parser 错误升级为 SystemError 时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。