qt5base-lts/tests/auto
Jüri Valdmann f43e947dc4 QJsonDocument: Make emptyObject an object
A default-constructed QJsonObject has no data payload, it is only a pair of null
pointers. So, when it becomes necessary to 'materialize' such an object, a
special global emptyObject constant is used as the substitute payload. There is
a small problem with this global constant though, namely that it's is_object
flag is unset. In other words, the emptyObject is not an object, but an array.

Fix by setting the is_object flag on emptyObject.

The example code in the bug report

    QJsonObject parent;
    QJsonObject child;
    parent["child"] = child;              // 1
    child = parent["child"].toObject();   // 2
    child["test"] = "test";               // 3

runs into this problem on line 1. Inserting the default-constructed child means
inserting a copy of emptyObject. On line 2 a pointer to this copy of emptyObject
is retrieved and cast to an object. But it's not an object, it's an array, so
things go wrong hereafter.

Specifically, on line 3, two inserts are performed, one from operator[] and one
from operator=. Each insert increments a compaction counter. The second insert
triggers compaction (QJsonObject::insert calls Value::requiredStorage calls
Data::compact) and compaction branches based on the is_object flag. Replacing
line 3 with

    child.insert("test", "test");

causes the example to appear to work since compaction is not triggered and the
JSON serializer does not look at the is_object flag. Still, any further insert()
calls would trigger compaction and memory corruption.

Task-number: QTBUG-69626
Change-Id: I8bd5174dce95998bac479c4b4ffea70bca1a4d04
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-07-31 09:33:42 +00:00
..
android Updated license headers 2016-01-21 18:55:18 +00:00
bic/data Add binary compatibility files for 5.11 for QtBase 2018-06-05 06:00:28 +00:00
cmake CMake: Restore qt5_use_modules() function 2018-06-15 07:29:09 +00:00
concurrent Fix of flaky qFutureAssignmentLeak test 2018-02-15 16:24:38 +00:00
corelib QJsonDocument: Make emptyObject an object 2018-07-31 09:33:42 +00:00
dbus tests/auto/dbus: Avoid unconditional qWait()s 2018-04-12 05:49:07 +00:00
gui Android: QEXPECT_FAIL tst_QTextDocument::task240325 2018-07-04 14:32:23 +00:00
guiapplauncher Fix path to examples part of tst_GuiAppLauncher 2015-02-13 07:28:15 +00:00
installed_cmake Add a unit test for testing Qt in its install location. 2013-07-02 23:08:54 +02:00
network tst_qnetworkinterface: Fix for case of zero interface 2018-07-06 06:39:36 +00:00
opengl tst_QGL: Use qWaitForWindowExposed() 2018-04-11 06:05:46 +00:00
other Reduce amount of log output of the qcomplextext autotest 2018-06-30 18:34:20 +00:00
printsupport If the page size is not valid on the new printer, set a custom size 2018-05-02 13:32:09 +00:00
shared Remove workaround for potentially unavailable pasteboard in macOS 2017-03-07 01:04:46 +00:00
sql Remove a reference to a no longer used database server 2018-05-16 14:40:19 +00:00
testlib Make tests compile for Android 2018-06-25 08:01:19 +00:00
tools qmake: make VFS aware of exact vs. cumulative evaluation 2018-03-29 18:15:10 +00:00
widgets Reset geometry constraints when removing stylesheet 2018-07-17 11:24:29 +00:00
xml Don't indefinitely wait for data if it was able to read some data 2018-01-24 05:54:31 +00:00
auto.pro tests/auto/auto.pro: Use correct null device for DBUS check 2017-12-01 09:53:07 +00:00
network-settings.h Merge remote-tracking branch 'origin/5.6' into 5.7 2016-05-06 15:36:44 +02:00