Multi-stream search panics on an empty `sql` list and on more `sql` entries than streams
Bug Description
Two request-controlled panics in the multi-stream search handlers (src/api/search/src/search/multi_streams.rs), both in the default build. Nothing catches either panic (tower-http is built without its catch-panic feature, and no build profile sets panic = "abort"), so the request that triggers it gets no HTTP response.
_search_multi divides by zero on an empty sql list. search_multi counts the queries before running them and divides by that count afterwards:
let mut queries = multi_req.to_query_req(); // :221
// …
let queries_len = queries.len(); // :232
// …
multi_res.cached_ratio /= queries_len; // :620cached_ratio is a usize (src/config/src/meta/search.rs:261), so with no queries this is an integer division by zero. Nothing rejects an empty list first. MultiStreamRequest.sql is #[serde(default, …)] (src/config/src/meta/search.rs:1285), so "sql": [] and a body with no sql field both deserialize to an empty Vec, and the decode loop (:227) and the query loop (:236) are no-ops.
The router already treats this as a client error: its body-based routing returns 400 Failed to parse multi search request for an empty sql (parse_querier_payload in src/api/http/src/router/http/mod.rs). That check only runs on a router node, and only when it routes by body, which needs the result cache on (ZO_RESULT_CACHE_ENABLED defaults to true but is cleared when the disk cache is off, src/config/src/config.rs:2241 and :4375). ZO_NODE_ROLE defaults to all (src/config/src/config.rs:1848), and is_router() checks only for Role::Router (src/config/src/meta/cluster.rs), so the default deployment, and every cluster node that is not a router, serves the handler directly.
_around_multi indexes out of bounds when sql has more entries than there are streams. around_multi builds one default SQL per stream named in the path, then overwrites them by position from the comma-separated sql query parameter (:902-913):
let mut around_sqls = stream_names
.iter()
.map(|name| format!("SELECT * FROM \"{name}\" "))
.collect::<Vec<String>>();
if let Some(v) = query.get("sql") {
let sqls = v.split(',').collect::<Vec<&str>>();
for (i, sql) in sqls.into_iter().enumerate() {
if let Ok(sql) = base64::decode_url(sql) {
around_sqls[i] = sql;
}
}
}Nothing compares the two counts, so with one stream a second sql entry that decodes panics at around_sqls[i]. _around_multi is proxied as a plain querier route: it matches ("_around", 3) in QUERIER_ROUTES and is not in QUERIER_ROUTES_BY_BODY (src/config/src/router.rs), so no router check sits in front of it.
Both handlers could return 400 before the panicking line: for an empty sql in search_multi, as the router already does, and for more sql entries than streams in around_multi.
Priority
P2 - Medium
Severity
Major
Related Story/Issue
Not Available. The same cached_ratio /= queries_len division is in search_service::search_multi (src/search_service/src/lib.rs), which the internal gRPC search_multi calls; I have not traced that path to user input.
Is this a regression?
No. Both look original to the handlers, but I have not confirmed that from history.
Steps to Reproduce (Optional)
On a node without the router role, which includes the default ZO_NODE_ROLE=all deployment:
POST /api/default/_search_multiwith{"sql": [], "start_time": 1, "end_time": 2}.GET /api/default/ZGVmYXVsdA../_around_multi?key=1&sql=U0VMRUNUICogRlJPTSAiZGVmYXVsdCI.,U0VMRUNUICogRlJPTSAiZGVmYXVsdCI.(one stream,default, and twosqlentries, eachSELECT * FROM "default", URL-safe base64 asconfig::utils::base64::encode_urlproduces it).
Expected: 400 for both.
Actual: the handler panics, with a division by zero at multi_streams.rs:620 and an index out of bounds at :910, and no response is sent.
Environment Details
Version: main at 8d91100b3 (Cargo.toml 0.93.0)
Build: default features (no enterprise)
Reproduced: traced through the source on main; not run against a server.Which OpenObserve Functionalities Are Affected?
- Home & Login
- Logs / Metrics / Traces
- Dashboards
- Alerts
- Streams, Pipelines & Functions
- Ingestion
- Real User Monitoring (RUM)
- Reports
- IAM & Management
- UI / Styling
- Unknown / Other
Source: openobserve/openobserve