From 2838544f7589c39bab9d63ff6db01ff5e82838eb Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 20 Jan 2025 22:52:22 +0100 Subject: [PATCH] decoder: Fix validating with different depth --- src/simdjson_decoder.cpp | 3 ++- tests/is_valid_depth.phpt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/is_valid_depth.phpt diff --git a/src/simdjson_decoder.cpp b/src/simdjson_decoder.cpp index 60db922..9ebea94 100644 --- a/src/simdjson_decoder.cpp +++ b/src/simdjson_decoder.cpp @@ -629,7 +629,7 @@ static simdjson_php_error_code simdjson_convert_element(simdjson::dom::element e } static simdjson_php_error_code simdjson_ondemand_validate(simdjson::ondemand::value element, size_t max_depth) { - if (UNEXPECTED(element.current_depth() > max_depth)) { + if (UNEXPECTED(element.current_depth() >= max_depth)) { return simdjson::DEPTH_ERROR; } @@ -676,6 +676,7 @@ PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_validate(simdjson_php_pars simdjson::ondemand::document doc; simdjson::ondemand::value value; + SIMDJSON_PHP_TRY(parser->ondemand_parser.allocate(ZSTR_LEN(json), depth)); SIMDJSON_PHP_TRY(parser->ondemand_parser.iterate(simdjson_padded_string_view(json, jsonbuffer)).get(doc)); if (SIMDJSON_PHP_VALUE(doc.is_scalar())) { return simdjson_ondemand_validate_scalar(&doc); diff --git a/tests/is_valid_depth.phpt b/tests/is_valid_depth.phpt new file mode 100644 index 0000000..4f405b6 --- /dev/null +++ b/tests/is_valid_depth.phpt @@ -0,0 +1,8 @@ +--TEST-- +simdjson_is_valid depth +--FILE-- + +--EXPECT-- +bool(false) \ No newline at end of file