From dd85987261fee92531d53d6640831103b535d8b8 Mon Sep 17 00:00:00 2001 From: jdymitarai Date: Thu, 8 Oct 2026 09:20:19 +0900 Subject: [PATCH] core: reduce MAX_PARSER_DEPTH to prevent stack overflow on deep nesting When parsing deeply nested structures (e.g. conditional branches, assert chains, or deep arrays), recursive descent parser calls consume stack frame space that can exhaust the thread stack under AddressSanitizer or default stack sizes before reaching MAX_PARSER_DEPTH = 1000. Lower MAX_PARSER_DEPTH to 500 to reliably trigger a controlled static error before stack memory exhaustion, preventing ASAN stack-overflow / SIGSEGV. Fixes #1117 --- core/parser.cpp | 2 +- test_suite/error.parse.deep_array_nesting.jsonnet.golden | 2 +- test_suite/error.parse.deep_if_nesting.jsonnet | 1 + test_suite/error.parse.deep_if_nesting.jsonnet.golden | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test_suite/error.parse.deep_if_nesting.jsonnet create mode 100644 test_suite/error.parse.deep_if_nesting.jsonnet.golden diff --git a/core/parser.cpp b/core/parser.cpp index 7b895f214..831b29875 100644 --- a/core/parser.cpp +++ b/core/parser.cpp @@ -60,7 +60,7 @@ static const Fodder EMPTY_FODDER; * This is especially important when parsing deeply nested structures that could lead to * excessive recursion in the parser functions. */ -static const unsigned MAX_PARSER_DEPTH = 1000; +static const unsigned MAX_PARSER_DEPTH = 500; static bool op_is_unary(const std::string &op, UnaryOp &uop) { diff --git a/test_suite/error.parse.deep_array_nesting.jsonnet.golden b/test_suite/error.parse.deep_array_nesting.jsonnet.golden index 94cc9a3d4..0b77c08b3 100644 --- a/test_suite/error.parse.deep_array_nesting.jsonnet.golden +++ b/test_suite/error.parse.deep_array_nesting.jsonnet.golden @@ -1 +1 @@ -STATIC ERROR: error.parse.deep_array_nesting.jsonnet:1:501: Exceeded maximum parse depth limit. +STATIC ERROR: error.parse.deep_array_nesting.jsonnet:1:251: Exceeded maximum parse depth limit. diff --git a/test_suite/error.parse.deep_if_nesting.jsonnet b/test_suite/error.parse.deep_if_nesting.jsonnet new file mode 100644 index 000000000..4117037a8 --- /dev/null +++ b/test_suite/error.parse.deep_if_nesting.jsonnet @@ -0,0 +1 @@ +if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else if true then 1 else 1 diff --git a/test_suite/error.parse.deep_if_nesting.jsonnet.golden b/test_suite/error.parse.deep_if_nesting.jsonnet.golden new file mode 100644 index 000000000..866a26ef2 --- /dev/null +++ b/test_suite/error.parse.deep_if_nesting.jsonnet.golden @@ -0,0 +1,2 @@ +STATIC ERROR: error.parse.deep_if_nesting.jsonnet:1:9984-9988: Exceeded maximum parse depth limit. +