Skip to content

Commit 2838544

Browse files
committed
decoder: Fix validating with different depth
1 parent 9a0f6ab commit 2838544

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/simdjson_decoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static simdjson_php_error_code simdjson_convert_element(simdjson::dom::element e
629629
}
630630

631631
static simdjson_php_error_code simdjson_ondemand_validate(simdjson::ondemand::value element, size_t max_depth) {
632-
if (UNEXPECTED(element.current_depth() > max_depth)) {
632+
if (UNEXPECTED(element.current_depth() >= max_depth)) {
633633
return simdjson::DEPTH_ERROR;
634634
}
635635

@@ -676,6 +676,7 @@ PHP_SIMDJSON_API simdjson_php_error_code php_simdjson_validate(simdjson_php_pars
676676
simdjson::ondemand::document doc;
677677
simdjson::ondemand::value value;
678678

679+
SIMDJSON_PHP_TRY(parser->ondemand_parser.allocate(ZSTR_LEN(json), depth));
679680
SIMDJSON_PHP_TRY(parser->ondemand_parser.iterate(simdjson_padded_string_view(json, jsonbuffer)).get(doc));
680681
if (SIMDJSON_PHP_VALUE(doc.is_scalar())) {
681682
return simdjson_ondemand_validate_scalar(&doc);

tests/is_valid_depth.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
simdjson_is_valid depth
3+
--FILE--
4+
<?php
5+
var_dump(simdjson_is_valid(str_repeat('[', 200000) . str_repeat(']', 199999), 5000));
6+
?>
7+
--EXPECT--
8+
bool(false)

0 commit comments

Comments
 (0)