alamb commented on code in PR #2400:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2400#discussion_r4423289679


##########
src/ast/spans.rs:
##########
@@ -3423,4 +3431,48 @@ SETTINGS update_parallel_mode = 'auto'"#;
             assert_eq!(test.get_source(expr.span()), expected, "{sql}");
         }
     }
+
+    #[test]
+    #[cfg(feature = "recursive-protection")]
+    fn test_deeply_nested_expr_span_does_not_overflow() {
+        // 200k nested nodes on a 512 KiB stack overflow unless the walk grows 
the stack.
+        std::thread::Builder::new()
+            .stack_size(512 * 1024)
+            .spawn(|| {
+                let mut expr = Expr::Identifier(crate::ast::Ident::new("x"));
+                for _ in 0..200_000 {
+                    expr = Expr::Nested(Box::new(expr));
+                }
+                let _ = expr.span();
+                // Dropping the chain recurses too; leak it so the test 
measures only the span walk.

Review Comment:
   If you can't drop the expression without overflowing the stack, I don't 
think allowing "spanned" to work is of much value
   
   If we really want to support OR chains with 200,000 items, I think we need 
to use a non tree representation (there is an open ticket for this)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to