qt6-bb10/tests/auto/corelib
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
..
animation qtbase: cleanup BLACKLIST files 2018-02-13 15:20:33 +00:00
codecs Replace Q_DECL_OVERRIDE with override where possible 2017-09-19 11:53:42 +00:00
global Android: fix tst_qlogging 2018-06-28 07:29:30 +00:00
io Fix the fix for mmap() overflow check 2018-07-25 12:40:04 +00:00
itemmodels QSFPM unittest: check dataChanged and layoutChanged signals 2018-07-28 12:26:41 +00:00
kernel Fix metatype trait for types that are both QObject and Q_GADGET 2018-06-30 13:23:03 +00:00
mimetypes QMimeDatabase: fix assert when fetching data for invalid mimetype 2018-04-06 07:19:01 +00:00
plugin tst_qpluginloader: Fix preprocessor condition 2018-07-27 04:48:30 +00:00
serialization QJsonDocument: Make emptyObject an object 2018-07-31 09:33:42 +00:00
statemachine tst_QStateMachine: Don't use unconditional waits 2018-04-04 07:07:40 +00:00
thread tst_qthreadpool: Skip "stackSize" if unsupported 2018-06-27 17:40:28 +00:00
tools Check against copying the husk left by a move 2018-07-26 16:35:59 +00:00
corelib.pro Create corelib/serialization and move existing file formats into it 2018-01-26 20:59:50 +00:00