Skip to content

Commit 47e8dcf

Browse files
authored
fix(normalization): Prevent stack overflow in sqlparser visitor (#5225)
Patch sub-dependency until apache/datafusion-sqlparser-rs#2060 has been merged. Fixes [POP-RELAY-37Q](https://sentry.my.sentry.io/organizations/sentry/issues/2423744/). Fixes INGEST-596.
1 parent 6f136e0 commit 47e8dcf

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,8 @@ utf16string = "0.2.0"
220220
uuid = { version = "1.11.0", features = ["serde", "v4", "v7"] }
221221
walkdir = "2.5.0"
222222
zstd = { version = "0.13.2", features = ["experimental"] }
223+
224+
# Patch until https://github.com/apache/datafusion-sqlparser-rs/pull/2060 has been merged.
225+
# This prevents stack overflows in span description normalization.
226+
[patch.crates-io]
227+
sqlparser_derive = { git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "ade40826563451cc14c130af9d689f4050dbdb15" }

relay-event-normalization/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ serde_json = { workspace = true }
3939
serde_urlencoded = { workspace = true }
4040
smallvec = { workspace = true }
4141
sqlparser = { workspace = true, features = ["visitor"] }
42-
4342
thiserror = { workspace = true }
4443
url = { workspace = true }
4544
uuid = { workspace = true }

relay-event-normalization/src/normalize/span/description/sql/parser.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ impl Dialect for DialectWithParameters {
870870

871871
#[cfg(test)]
872872
mod tests {
873+
use sqlparser::ast::{Visit, Visitor};
874+
873875
use super::*;
874876

875877
#[test]
@@ -881,6 +883,32 @@ mod tests {
881883
);
882884
}
883885

886+
#[test]
887+
fn visit_deep_expression() {
888+
struct TestVisitor;
889+
impl Visitor for TestVisitor {
890+
type Break = ();
891+
}
892+
let leaf = || Box::new(Expr::Value(Value::Null.into()));
893+
let op = BinaryOperator::And;
894+
895+
let mut expr = Expr::BinaryOp {
896+
left: leaf(),
897+
op,
898+
right: leaf(),
899+
};
900+
901+
for _ in 0..10_000 {
902+
expr = Expr::BinaryOp {
903+
left: Box::new(expr),
904+
op: BinaryOperator::And,
905+
right: leaf(),
906+
}
907+
}
908+
909+
let _ = expr.visit(&mut TestVisitor);
910+
}
911+
884912
#[test]
885913
fn parse_dont_panic() {
886914
assert!(parse_query_inner(None, "REPLACE g;'341234c").is_err());

0 commit comments

Comments
 (0)