diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 13:54:48 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 13:54:48 +0200 |
| commit | 93fd7757dc4900da697b9d5e884e1a343e2facda (patch) | |
| tree | 91faf28e84d65269a0328e2e7f5934e253886af5 /src/ast.rs | |
| parent | 4710b5224f24992dabb2a2dd9230cac586f20ffd (diff) | |
| download | ele-93fd7757dc4900da697b9d5e884e1a343e2facda.tar.gz ele-93fd7757dc4900da697b9d5e884e1a343e2facda.zip | |
Bound filter parsing and reject excessive expression depth
Diffstat (limited to 'src/ast.rs')
| -rw-r--r-- | src/ast.rs | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -104,3 +104,33 @@ pub enum Expr { args: Vec<Expr>, }, } + +impl Expr { + pub(crate) fn check_limits(&self) -> Result<(), String> { + let mut pending = vec![(self, 1)]; + let mut count = 0; + while let Some((expr, depth)) = pending.pop() { + count += 1; + if depth > 128 || count > 512 { + return Err("filter exceeds expression limit (128 levels, 512 nodes)".into()); + } + match expr { + Expr::Binary { left, right, .. } | Expr::Comparison { left, right, .. } => { + pending.push((left, depth + 1)); + pending.push((right, depth + 1)); + } + Expr::Unary { expr, .. } => pending.push((expr, depth + 1)), + Expr::Member { holder, .. } => pending.push((holder, depth + 1)), + Expr::Function { func, args } => { + if args.len() > 512 { + return Err("filter exceeds expression limit (512 nodes)".into()); + } + pending.push((func, depth + 1)); + pending.extend(args.iter().map(|arg| (arg, depth + 1))); + } + Expr::Name { .. } => {} + } + } + Ok(()) + } +} |
