
SQLite 3.53.4 - Alta - Locale - Crash - le CTE annidate ignorano il limite di profondità della vista nNestSel
abraxaslabs.tech · github.com/abraxas · @abraxas_null · [email protected] · sqlite-cte-nest
Write-up: https://abraxaslabs.tech/research/sqlite-cte-nest
Class: Crash Reach: Local
SQLite 3.53.4 (b09c88c14082339b66c7b7158d609a771e64ca69, SOURCE_ID 2026-07-24 19:02:57 bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bcc) - Hwaci
sqlite3ResultSetOfSelect incrementa nNestSel e restituisce l'errore VIEWs and/or subqueries nested too deep quando la catena raggiunge SQLITE_LIMIT_EXPR_DEPTH. Le VIEW annidate su questa versione raggiungono già quel limite. L'aggancio delle CTE in select.c:5754 (sqlite3SrcItemAttachSubquery) non incrementa nNestSel. selectExpander / sqlite3WalkSelect ricorre quindi sulla catena di CTE finché lo stack C non collassa.
Una piccola catena di CTE restituisce una riga. Il FROM annidato a N=25000 produce un Recursion limit del parser e non causa crash. Le VIEW annidate con .limit expr_depth 20 restituiscono l'errore too-deep. La CTE con N=25000 provoca uno stack-overflow ASan. Non è RCE.
| ID | nessuna CVE al momento |
| Class | Crash (stack-overflow ASan in selectExpander; RCE non dimostrata) |
| Reach | Local (SQL non attendibile o schema con CTE annidate) |
| CWE | CWE-674 |
| CVSS | High: 7.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| Product | SQLite (mirror GitHub sqlite/sqlite) |
| Affected | 3.53.4 (b09c88c); residuo del nNestSel delle CTE del trunk successivo |
| Auth | SQL non attendibile o una catena WITH inserita ad arte |
| License | GNU Affero GPL v3.0 |
| Lab | solo 127.0.0.1:18810. Amalgamation ASan. Crash witness. |
Fornire una lunga catena di CTE, come SQL o come corpo di una VIEW su un .db non attendibile:
WITH c0 AS (SELECT 1),
c1 AS (SELECT * FROM c0),
...
cN AS (SELECT * FROM cN-1)
SELECT * FROM cN;
selectExpander percorre ogni CTE come una sottoquery FROM annidata. nNestSel non si sposta mai. Il processo host muore sullo stack C. Le VIEW annidate sono già limitate. Il FROM annidato raggiunge il limite di ricorsione del parser. Questo residuo è il percorso di attach delle CTE. SQLite non valuta i nomi delle CTE in una shell. Crash, non RCE.
Venti ricerche nel codice sorgente di https://github.com/sqlite/sqlite tag https://github.com/sqlite/sqlite/releases/tag/version-3.53.4. Le VIEW annidate erano limitate su questo pin (3f3fb9b638 / branch-3.53 38430aa5ed, 2026-06-16). L'attach delle CTE non lo era. Il trunk f547308713 (2026-10-05) è successivo a questa GA.
Vicoli ciechi già registrati: considerare le VIEW annidate come il crash (restituiscono un errore too-deep); considerare il FROM annidato N=25000 come il crash (parser Recursion limit); prendere una catena di 5 CTE come prova che il limite si applichi.
cd lab
./run.sh
Zip ufficiale sqlite-src-3530400, amalgamazione ASan, compose sqlite-cte-nest, pubblicato 127.0.0.1:18810. Associalo al loopback. Non puntare questo a SQLite di qualcun altro.
SUCCESS sqlite-cte-nest how=asan-stack-overflow crash-n=25000 small-cte=ok nested-views=too-deep nested-from=rejected SQLITE-CTE-NEST-WITNESS
Incrementare nNestSel al collegamento della CTE nello stesso modo in cui sqlite3ResultSetOfSelect già fa per le VIEW, e generare un errore a SQLITE_LIMIT_EXPR_DEPTH. Il trunk f547308713 (2026-10-05, "Limit the depth of recursion for CTEs using SQLITE_LIMIT_EXPR_DEPTH") è quella classe di patch. Non è presente nella 3.53.4.
b09c88c14082339b66c7b7158d609a771e64ca69)2026-07-24 19:02:57 bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bccsrc/select.c sqlite3ResultSetOfSelect (nNestSel++), collegamento CTE :5754src/walker.c sqlite3WalkSelectFrom subquery walkselectExpander / sqlite3SelectExpand2026-10-04T04:58:58Z; trunk f547308713