python / python/cpython

Quadratic time in `xml.etree.ElementTree` when parsing text with a large number of comments

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

还没有人认领这个 Issue。

extension-modules topic-XML type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
import time
import xml.etree.ElementTree as ET

for N in (5000, 10000, 20000, 40000, 80000):
    data = b"<r>" + b"x<!---->" * N + b"</r>"
    s = time.perf_counter()
    ET.fromstring(data)
    dt = time.perf_counter() - s
    print(f"{N}  {dt}s")

I see:

$ python repro.py 
5000  0.025435873976675794s
10000  0.0888163199997507s
20000  0.3610062320076395s
40000  1.4099939750158228s
80000  5.41402202800964s

Found by OSS-Fuzz.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-155407

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 issue 中的 ET.fromstring() 复现代码开始,并比较评论数量增加时的耗时。查看链接的 PR gh-155407,以了解已经在进行的工作;当解析此输入不再显示二次时间增长时,即视为完成。

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

评估

技术栈
python
领域
performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

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