Skip to content

Commit

Permalink
CBL 5311 : Increase Rev Tree Depth Limit to 100. (#215)
Browse files Browse the repository at this point in the history
This requires to increase the static limit of depth that the JSON parser can handle.

Ported from CBL 5124
  • Loading branch information
jianminzhao committed Apr 1, 2024
1 parent 8f89a3b commit 82e9acc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Fleece/Core/JSONConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace fleece { namespace impl {

JSONConverter::JSONConverter(Encoder &e) noexcept
:_encoder(e),
_jsn(jsonsl_new(50)), // never returns nullptr, according to source code
_jsn(jsonsl_new(102)), // never returns nullptr, according to source code. 102 allows 100 logical levels.
_jsonError(JSONSL_ERROR_SUCCESS),
_errorPos(0)
{
Expand Down
37 changes: 37 additions & 0 deletions Tests/ValueTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,41 @@ namespace fleece {
// (calling FLDictIterator_Next would be illegal)
FLDoc_Release(doc);
}

TEST_CASE("Many Levels in a Doc", "[Doc]") {
auto genDoc = [](unsigned nlevels) -> string {
// pre-condition: nlevels >= 1
string ret = "";
for (unsigned i = 1; i <= nlevels; ++i) {
ret += R"({"a":)";
}
ret += "1}";
for (unsigned i = 2; i <= nlevels; ++i) {
ret += "}";
}
return ret;
};

SECTION("100 Levels of JSON Dictionary") {
alloc_slice origJSON{genDoc(100)};
Retained<Doc> doc = Doc::fromJSON(origJSON);
auto root = doc->root();
alloc_slice json = root->toJSON();
CHECK(origJSON == json);
retain(root);
release(root);
}

SECTION("100 Is the Limit of JSON Dictionary") {
alloc_slice origJSON{genDoc(101)};
Retained<Doc> doc;
fleece::ErrorCode errCode = fleece::NoError;
try {
doc = Doc::fromJSON(origJSON);
} catch (FleeceException& exc) {
errCode = fleece::JSONError;
}
CHECK(errCode == fleece::JSONError);
}
}
}

0 comments on commit 82e9acc

Please sign in to comment.