Skip to content

Commit

Permalink
CBL-5124: Increase Rev Tree Depth Limit to 100. (#197)
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.
  • Loading branch information
jianminzhao authored Nov 28, 2023
1 parent 7cf5da5 commit f13c0b6
Show file tree
Hide file tree
Showing 3 changed files with 40 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 @@ -232,4 +232,41 @@ namespace fleece {
docs.push_back(Doc::fromJSON("[]"));
}
}

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);
}
}
}
2 changes: 2 additions & 0 deletions Xcode/xcconfigs/FleeceTest.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ MACOSX_DEPLOYMENT_TARGET = 10.14
CLANG_WARN__EXIT_TIME_DESTRUCTORS = NO
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) _LIBCPP_DEBUG=0
RUN_CLANG_STATIC_ANALYZER = NO

CODE_SIGNING_ALLOWED = NO

0 comments on commit f13c0b6

Please sign in to comment.