validate() allocates program-declared sizes and loop ranges in check-only mode (resource exhaustion from a small QASM file)

未关闭
#496 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
43/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, security

调研方向

Read src/pyqasm/modules/base.py around QasmModule.validate() and the cited allocation and loop paths in src/pyqasm/visitor.py; inspect src/pyqasm/maps/expressions.py for the array dimension limit. Start by tracing how check-only validation handles declared registers, arrays, and loops, then add bounds or check-only exits with tests for small programs that trigger large allocations or long loops. Done means validation rejects or safely handles these cases without exhausting resources.

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

描述

Note: your SECURITY.md asks for reports through the private advisory form, but private vulnerability reporting is turned off for this repository, so the form isn't available. That is the only reason we're reporting this publicly. We also emailed [email protected] today asking for a private channel.

Our code review of qBraid/pyqasm at 95747c7bea4b73f6065249e708071fc5b3bdc461 (current main; pyproject version 1.4.0, three commits after the v1.4.0 tag) found that QasmModule.validate() still materialises program-declared sizes and loop ranges in check-only mode, so a short OpenQASM program can force a large allocation or a long loop.

validate() (src/pyqasm/modules/base.py:709–727) builds a QasmVisitor with check_only=True (line 715) and walks the program. A classical bit register is initialised with np.full of the declared length (src/pyqasm/visitor.py:2067–2069) and then one dict entry and one ClbitDepthNode per bit (lines 2212–2214) before the check-only return at line 2236. An array is similarly allocated with np.full (line 2097) after only the number of dimensions is capped (MAX_ARRAY_DIMENSIONS = 7 in src/pyqasm/maps/expressions.py:185), not the product of their sizes. A qubit register adds one label and one QubitDepthNode per qubit (visitor.py:309–312) with no size cap; validate()'s later device_qubits check (base.py:718) applies only if the caller set that option, which defaults to None (base.py:206). A for-loop range is turned into a list (visitor.py:2586) before the existing iteration-limit check (line 2601, default 1e9). A while loop has no check-only exit (unlike the for loop at line 2646) and runs until that same counter (lines 2841–2904, counter at 2895); a continue in the body jumps back without incrementing the counter (lines 2881–2887). The bundled CLI pyqasm validate <file> calls load() then validate() (src/pyqasm/cli/validate.py:74–75). This is a source review only, nothing was run or compiled.

This is an availability issue only: a caller that validates QASM it did not write (a service, a CI job, or the CLI) can be stalled or run out of memory by a small file. We have not claimed a particular hosted service. A suggested untested fix (caps on register and array sizes before allocation, a lazy for-loop range, and a check-only exit for while, plus tests) is available on request. The numeric caps in that patch are a policy choice for you to set.

Credit: Ugur Celik (ucsurf), @ucsurf

— ucsurf / https://uc.surf
If you'd like to support our work, even a coffee helps: https://buymeacoffee.com/ucsurf

主要语言
Python
星标
29
派生
33
平均合并
1 天 20 小时
30 天内合并 PR
8

环境准备

从这里开始

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

qBraid/pyqasm 的其他 Issue

查看 qBraid/pyqasm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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