Skip to content

Commit

Permalink
decoder: Fix validating with different depth
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubOnderka committed Jan 20, 2025
1 parent 9a0f6ab commit 2838544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/simdjson_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/is_valid_depth.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
simdjson_is_valid depth
--FILE--
<?php
var_dump(simdjson_is_valid(str_repeat('[', 200000) . str_repeat(']', 199999), 5000));
?>
--EXPECT--
bool(false)

0 comments on commit 2838544

Please # to comment.