@@ -516,6 +516,101 @@ TEST(lsp_ts_cyclic_types_no_crash) {
516516 PASS ();
517517}
518518
519+ /* ─── Deeply-nested calls drive the per-language LSP resolve walkers into
520+ * per-nesting-level native recursion. Unguarded, these SIGSEGV and take down
521+ * the whole index. Each walker now has a walk_depth cap (CBM_LSP_MAX_WALK_DEPTH,
522+ * env-overridable) that skips the too-deep subtree — graceful degradation.
523+ * These mirror lsp_java_deep_nesting_no_crash: same fixture shape, one per
524+ * previously-unguarded walker (py_resolve_calls_in, resolve_calls_in_node[go],
525+ * php_resolve_calls_in_node, kt_resolve_calls_in_node). RED proof: run the
526+ * suite with CBM_LSP_MAX_WALK_DEPTH set huge (disabling only these caps) and
527+ * each of these four SIGSEGVs — proving the guard, not the fixture, is what
528+ * keeps them green. ─── */
529+
530+ TEST (lsp_python_deep_nesting_no_crash ) {
531+ /* py_resolve_calls_in recurses per nesting level; see the Java analog. */
532+ const int DEPTH = 30000 ;
533+ size_t sz = (size_t )DEPTH * 3 + 256 ;
534+ char * src = malloc (sz );
535+ ASSERT_NOT_NULL (src );
536+ char * p = src ;
537+ p += snprintf (p , sz , "def f(a):\n return a\ndef g():\n return " );
538+ for (int i = 0 ; i < DEPTH ; i ++ ) {
539+ * p ++ = 'f' ;
540+ * p ++ = '(' ;
541+ }
542+ * p ++ = '1' ;
543+ memset (p , ')' , DEPTH );
544+ p += DEPTH ;
545+ snprintf (p , sz - (size_t )(p - src ), "\n" );
546+ ASSERT_FALSE (so_extract_crashes (src , CBM_LANG_PYTHON , "deep.py" ));
547+ free (src );
548+ PASS ();
549+ }
550+
551+ TEST (lsp_go_deep_nesting_no_crash ) {
552+ /* resolve_calls_in_node recurses per nesting level; see the Java analog. */
553+ const int DEPTH = 30000 ;
554+ size_t sz = (size_t )DEPTH * 3 + 256 ;
555+ char * src = malloc (sz );
556+ ASSERT_NOT_NULL (src );
557+ char * p = src ;
558+ p += snprintf (p , sz , "package p\nfunc f(a int) int { return a }\nfunc g() int { return " );
559+ for (int i = 0 ; i < DEPTH ; i ++ ) {
560+ * p ++ = 'f' ;
561+ * p ++ = '(' ;
562+ }
563+ * p ++ = '1' ;
564+ memset (p , ')' , DEPTH );
565+ p += DEPTH ;
566+ snprintf (p , sz - (size_t )(p - src ), " }\n" );
567+ ASSERT_FALSE (so_extract_crashes (src , CBM_LANG_GO , "deep.go" ));
568+ free (src );
569+ PASS ();
570+ }
571+
572+ TEST (lsp_php_deep_nesting_no_crash ) {
573+ /* php_resolve_calls_in_node recurses per nesting level; Java analog. */
574+ const int DEPTH = 30000 ;
575+ size_t sz = (size_t )DEPTH * 3 + 256 ;
576+ char * src = malloc (sz );
577+ ASSERT_NOT_NULL (src );
578+ char * p = src ;
579+ p += snprintf (p , sz , "<?php\nfunction f($a) { return $a; }\nfunction g() { return " );
580+ for (int i = 0 ; i < DEPTH ; i ++ ) {
581+ * p ++ = 'f' ;
582+ * p ++ = '(' ;
583+ }
584+ * p ++ = '1' ;
585+ memset (p , ')' , DEPTH );
586+ p += DEPTH ;
587+ snprintf (p , sz - (size_t )(p - src ), "; }\n" );
588+ ASSERT_FALSE (so_extract_crashes (src , CBM_LANG_PHP , "deep.php" ));
589+ free (src );
590+ PASS ();
591+ }
592+
593+ TEST (lsp_kotlin_deep_nesting_no_crash ) {
594+ /* kt_resolve_calls_in_node recurses per nesting level; Java analog. */
595+ const int DEPTH = 30000 ;
596+ size_t sz = (size_t )DEPTH * 3 + 256 ;
597+ char * src = malloc (sz );
598+ ASSERT_NOT_NULL (src );
599+ char * p = src ;
600+ p += snprintf (p , sz , "fun f(a: Int): Int { return a }\nfun g(): Int { return " );
601+ for (int i = 0 ; i < DEPTH ; i ++ ) {
602+ * p ++ = 'f' ;
603+ * p ++ = '(' ;
604+ }
605+ * p ++ = '1' ;
606+ memset (p , ')' , DEPTH );
607+ p += DEPTH ;
608+ snprintf (p , sz - (size_t )(p - src ), " }\n" );
609+ ASSERT_FALSE (so_extract_crashes (src , CBM_LANG_KOTLIN , "deep.kt" ));
610+ free (src );
611+ PASS ();
612+ }
613+
519614/* ═══════════════════════════════════════════════════════════════════
520615 * Suite registration
521616 * ═══════════════════════════════════════════════════════════════════ */
@@ -529,6 +624,10 @@ SUITE(stack_overflow) {
529624 RUN_TEST (lsp_java_lambda_args_exceed_params_no_crash );
530625 RUN_TEST (lsp_cpp_deep_expression_no_crash );
531626 RUN_TEST (lsp_ts_cyclic_types_no_crash );
627+ RUN_TEST (lsp_python_deep_nesting_no_crash );
628+ RUN_TEST (lsp_go_deep_nesting_no_crash );
629+ RUN_TEST (lsp_php_deep_nesting_no_crash );
630+ RUN_TEST (lsp_kotlin_deep_nesting_no_crash );
532631
533632 RUN_TEST (js_calls_exceed_512 );
534633 RUN_TEST (python_calls_exceed_512 );
0 commit comments