diff --git a/crates/jsonrpc/src/control.rs b/crates/jsonrpc/src/control.rs index f52e294b7..ed3729329 100644 --- a/crates/jsonrpc/src/control.rs +++ b/crates/jsonrpc/src/control.rs @@ -7,13 +7,13 @@ use std::fmt::Display; /// Process one bounded control line. Blank lines yield no response. Missing `params` becomes null; /// arbitrary JSON ids are echoed and malformed JSON has a null id, matching the legacy protocol. pub fn process_line(line: &str, max_bytes: usize, dispatch: impl FnOnce(&str, &Value) -> Result) -> Option { + if line.len() > max_bytes { + return Some(error(None, "request exceeds byte limit")); + } let trimmed = line.trim(); if trimmed.is_empty() { return None; } - if line.len() > max_bytes { - return Some(error(None, "request exceeds byte limit")); - } let value: Value = match serde_json::from_str(trimmed) { Ok(v) => v, Err(e) => return Some(error(None, &format!("bad request envelope: {e}"))),