diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-04-01 08:45:54 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-04-01 08:45:54 +0000 |
commit | 201a7320f48b1d8868bc1fb38ee1182ad3d84dd7 (patch) | |
tree | d3591478e3a024d6f4a39c76b49ffc66885dd918 /document | |
parent | 013342a0470e7a5b456921010009c38a4a0c828f (diff) |
Add more limit details to parse failure messages
Diffstat (limited to 'document')
-rw-r--r-- | document/src/tests/documentselectparsertest.cpp | 10 | ||||
-rw-r--r-- | document/src/vespa/document/select/parser.cpp | 4 | ||||
-rw-r--r-- | document/src/vespa/document/select/parser_limits.cpp | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index fce0d90db72..2d2b7bfd085 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -1611,7 +1611,7 @@ TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_field_exprs) { expr += ".foo"; } expr += ".hash() != 0"; - verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested"); + verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested (max 1024 levels)"); } TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_arithmetic_exprs) { @@ -1621,7 +1621,7 @@ TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_arithmetic_exprs expr += "+1"; } expr += " != 0"; - verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested"); + verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested (max 1024 levels)"); } TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_binary_logical_exprs) { @@ -1632,7 +1632,7 @@ TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_binary_logical_e for (size_t i = 0; i < 10000; ++i) { expr += (i % 2 == 0 ? " and " : " or ") + cmp_subexpr; } - verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested"); + verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested (max 1024 levels)"); } TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_unary_logical_exprs) { @@ -1642,7 +1642,7 @@ TEST_F(DocumentSelectParserTest, recursion_depth_is_bounded_for_unary_logical_ex expr += "not "; } expr += "true"; - verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested"); + verifyFailedParse(expr, "ParsingFailedException: expression is too deeply nested (max 1024 levels)"); } TEST_F(DocumentSelectParserTest, selection_has_upper_limit_on_input_size) { @@ -1650,7 +1650,7 @@ TEST_F(DocumentSelectParserTest, selection_has_upper_limit_on_input_size) { std::string expr = ("testdoctype1.a_biii" + std::string(select::ParserLimits::MaxSelectionByteSize, 'i') + "iiig_identifier"); - verifyFailedParse(expr, "ParsingFailedException: expression is too large to be parsed"); + verifyFailedParse(expr, "ParsingFailedException: expression is too large to be parsed (max 1048576 bytes)"); } TEST_F(DocumentSelectParserTest, lexing_does_not_have_superlinear_time_complexity) { diff --git a/document/src/vespa/document/select/parser.cpp b/document/src/vespa/document/select/parser.cpp index df8659d22f4..f7c2bebb007 100644 --- a/document/src/vespa/document/select/parser.cpp +++ b/document/src/vespa/document/select/parser.cpp @@ -13,7 +13,9 @@ namespace { void verify_expression_not_too_large(const std::string& expr) { if (expr.size() > ParserLimits::MaxSelectionByteSize) { - throw ParsingFailedException("expression is too large to be parsed"); + throw ParsingFailedException(vespalib::make_string( + "expression is too large to be parsed (max %zu bytes)", + ParserLimits::MaxSelectionByteSize)); } } diff --git a/document/src/vespa/document/select/parser_limits.cpp b/document/src/vespa/document/select/parser_limits.cpp index 7f5715517c6..13e494b376f 100644 --- a/document/src/vespa/document/select/parser_limits.cpp +++ b/document/src/vespa/document/select/parser_limits.cpp @@ -1,11 +1,13 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "parser_limits.h" #include "parsing_failed_exception.h" +#include <vespa/vespalib/util/stringfmt.h> namespace document::select { void throw_max_depth_exceeded_exception() { - throw ParsingFailedException("expression is too deeply nested"); + throw ParsingFailedException(vespalib::make_string( + "expression is too deeply nested (max %u levels)", ParserLimits::MaxRecursionDepth)); } } |