validate() allocates program-declared sizes and loop ranges in check-only mode (resource exhaustion from a small QASM file)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qBraid/pyqasm 的其他 Issue
-
dumps() prints the original program when unroll() leaves at most one statement可能已有人在做 @ShiveshDragon 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
enhancement error-handling program-validation
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
dependencies enhancement
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
Integer division for casts, int array elements, bitwise results, ** and int-returning subroutines未关闭
难度 3/5 1-2 天 新手友好度 52/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
521xueweihan/HelloGitHub#4729 ·
-
auto-reported bug
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
needs-triage type:bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
pollen-robotics/reachy_mini_conversation_app#631 ·
维护者通常 7 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100