summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 84913f9289..00810889bb 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -127,6 +127,7 @@ private Q_SLOTS:
void valueEquals();
void bom();
+ void nesting();
private:
QString testDataDir;
};
@@ -1924,5 +1925,64 @@ void TestQtJson::bom()
QVERIFY(error.error == QJsonParseError::NoError);
}
+void TestQtJson::nesting()
+{
+ // check that we abort parsing too deeply nested json documents.
+ // this is to make sure we don't crash because the parser exhausts the
+ // stack.
+
+ const char *array_data =
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
+ "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
+ "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
+ "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
+ "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]";
+
+ QByteArray json(array_data);
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(json, &error);
+
+ QVERIFY(!doc.isNull());
+ QVERIFY(error.error == QJsonParseError::NoError);
+
+ json.prepend("[");
+ json.append("]");
+ doc = QJsonDocument::fromJson(json, &error);
+
+ QVERIFY(doc.isNull());
+ QVERIFY(error.error == QJsonParseError::DeepNesting);
+
+ json = QByteArray("true ");
+
+ for (int i = 0; i < 1024; ++i) {
+ json.prepend("{ \"Key\": ");
+ json.append(" }");
+ }
+
+ doc = QJsonDocument::fromJson(json, &error);
+
+ QVERIFY(!doc.isNull());
+ QVERIFY(error.error == QJsonParseError::NoError);
+
+ json.prepend("[");
+ json.append("]");
+ doc = QJsonDocument::fromJson(json, &error);
+
+ QVERIFY(doc.isNull());
+ QVERIFY(error.error == QJsonParseError::DeepNesting);
+
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"