diff --git a/Cargo.lock b/Cargo.lock index 57041fbbb8..6f5989ac14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5220,8 +5220,7 @@ dependencies = [ [[package]] name = "sqlparser_derive" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da5fc6819faabb412da764b99d3b713bb55083c11e7e0c00144d386cd6a1939c" +source = "git+https://github.com/apache/datafusion-sqlparser-rs?rev=ade40826563451cc14c130af9d689f4050dbdb15#ade40826563451cc14c130af9d689f4050dbdb15" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 2a7ce5a223..5b4271a259 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -220,3 +220,8 @@ utf16string = "0.2.0" uuid = { version = "1.11.0", features = ["serde", "v4", "v7"] } walkdir = "2.5.0" zstd = { version = "0.13.2", features = ["experimental"] } + +# Patch until https://github.com/apache/datafusion-sqlparser-rs/pull/2060 has been merged. +# This prevents stack overflows in span description normalization. +[patch.crates-io] +sqlparser_derive = { git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "ade40826563451cc14c130af9d689f4050dbdb15" } diff --git a/relay-event-normalization/Cargo.toml b/relay-event-normalization/Cargo.toml index 9e196a75ce..6770bc3229 100644 --- a/relay-event-normalization/Cargo.toml +++ b/relay-event-normalization/Cargo.toml @@ -39,7 +39,6 @@ serde_json = { workspace = true } serde_urlencoded = { workspace = true } smallvec = { workspace = true } sqlparser = { workspace = true, features = ["visitor"] } - thiserror = { workspace = true } url = { workspace = true } uuid = { workspace = true } diff --git a/relay-event-normalization/src/normalize/span/description/sql/parser.rs b/relay-event-normalization/src/normalize/span/description/sql/parser.rs index ca9ba45026..e15871ff5a 100644 --- a/relay-event-normalization/src/normalize/span/description/sql/parser.rs +++ b/relay-event-normalization/src/normalize/span/description/sql/parser.rs @@ -870,6 +870,8 @@ impl Dialect for DialectWithParameters { #[cfg(test)] mod tests { + use sqlparser::ast::{Visit, Visitor}; + use super::*; #[test] @@ -881,6 +883,32 @@ mod tests { ); } + #[test] + fn visit_deep_expression() { + struct TestVisitor; + impl Visitor for TestVisitor { + type Break = (); + } + let leaf = || Box::new(Expr::Value(Value::Null.into())); + let op = BinaryOperator::And; + + let mut expr = Expr::BinaryOp { + left: leaf(), + op, + right: leaf(), + }; + + for _ in 0..10_000 { + expr = Expr::BinaryOp { + left: Box::new(expr), + op: BinaryOperator::And, + right: leaf(), + } + } + + let _ = expr.visit(&mut TestVisitor); + } + #[test] fn parse_dont_panic() { assert!(parse_query_inner(None, "REPLACE g;'341234c").is_err());