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

Abierto
#496 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
43/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend, security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
29
Forks
33
Merge medio
1 d 20 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de qBraid/pyqasm

Todos los issues de qBraid/pyqasm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.