diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-11-02 14:10:47 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-11-11 12:34:27 +0000 |
commit | bfaa8925d5cc0a59cec3f747a8d982ca819f026b (patch) | |
tree | f50e0fde4e197fee070fc2906b16085352b45328 /tests/auto/corelib/json/tst_qtjson.cpp | |
parent | 3c2cb87de2554b9c4f6e2080768fe9ede00aeab3 (diff) |
Improve the validation algorithm for binary JSON
Add better boundary checks and catch (hopefully all)
cases where invalid binary JSON could cause crashes.
Change-Id: I206510b7c5e3ba953802a5f46645878e65704ecc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/json/tst_qtjson.cpp')
-rw-r--r-- | tests/auto/corelib/json/tst_qtjson.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 1665ff696d..f2f9166711 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -103,6 +103,7 @@ private Q_SLOTS: void fromBinary(); void toAndFromBinary_data(); void toAndFromBinary(); + void invalidBinaryData(); void parseNumbers(); void parseStrings(); void parseDuplicateKeys(); @@ -1779,6 +1780,21 @@ void tst_QtJson::toAndFromBinary() QVERIFY(doc == outdoc); } +void tst_QtJson::invalidBinaryData() +{ + QDir dir(testDataDir + "/invalidBinaryData"); + QFileInfoList files = dir.entryInfoList(); + for (int i = 0; i < files.size(); ++i) { + if (!files.at(i).isFile()) + continue; + QFile file(files.at(i).filePath()); + file.open(QIODevice::ReadOnly); + QByteArray bytes = file.readAll(); + QJsonDocument document = QJsonDocument::fromRawData(bytes.constData(), bytes.size()); + QVERIFY(document.isNull()); + } +} + void tst_QtJson::parseNumbers() { { |