expression
Bound JSON input before parsing
Enforce byte limits before parsing an already bounded buffer. For a network or file stream, cap the read itself; this check alone cannot recover memory already allocated. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): true too large Common mistake: Believing a byte limit is also a complete depth, time or authorization policy.
Formal Syntax & Structure
rust syntaxrust
if input.len() > LIMIT { reject }Working Example
Example Snippetrust
fn main() { fn parse_small(s: &str) -> Result<serde_json::Value, &'static str> { if s.len() > 16 { return Err("too large"); } serde_json::from_str(s).map_err(|_| "invalid JSON") } println!("{}", parse_small("[1,2]").is_ok()); println!("{}", parse_small("[1234567890123456789]").unwrap_err());}