diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2015-05-21 16:12:22 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2015-05-21 16:12:22 +0100 |
commit | e2e4c36b358bc31cb03e934084cacbff1966c39d (patch) | |
tree | cc124e9e78c80729cb32443c304016d27fcb8998 /gui | |
parent | 8408237a4e46e89488bef95f7f7c50b312f7c1aa (diff) |
gui: Try to cope with incomplete UBJSON.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/qubjson.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/gui/qubjson.cpp b/gui/qubjson.cpp index 68ca4fc4..01b653c7 100644 --- a/gui/qubjson.cpp +++ b/gui/qubjson.cpp @@ -40,9 +40,12 @@ using namespace ubjson; static Marker readMarker(QDataStream &stream) { + if (stream.atEnd()) { + return MARKER_EOF; + } quint8 byte; stream >> byte; - return static_cast<ubjson::Marker>(byte); + return static_cast<Marker>(byte); } @@ -122,6 +125,7 @@ readSize(QDataStream &stream) return readInt64(stream); default: Q_UNIMPLEMENTED(); + case MARKER_EOF: return 0; } } @@ -150,19 +154,23 @@ readArray(QDataStream &stream) if (marker == MARKER_TYPE) { Marker type = readMarker(stream); Q_ASSERT(type == MARKER_UINT8); + Q_UNUSED(type); marker = readMarker(stream); Q_ASSERT(marker == MARKER_COUNT); size_t count = readSize(stream); QByteArray array(count, Qt::Uninitialized); int read = stream.readRawData(array.data(), count); Q_ASSERT(read == count); + Q_UNUSED(read); marker = readMarker(stream); Q_ASSERT(marker == MARKER_ARRAY_END); + Q_UNUSED(marker); return array; } else { Q_ASSERT(marker != MARKER_COUNT); QVariantList array; - while (marker != MARKER_ARRAY_END) { + while (marker != MARKER_ARRAY_END && + marker != MARKER_EOF) { QVariant value = readVariant(stream, marker); array.append(value); marker = readMarker(stream); @@ -177,7 +185,8 @@ readObject(QDataStream &stream) { QVariantMap object; Marker marker = readMarker(stream); - while (marker != MARKER_OBJECT_END) { + while (marker != MARKER_OBJECT_END && + marker != MARKER_EOF) { Q_ASSERT(marker == MARKER_STRING); QString name = readString(stream); marker = readMarker(stream); @@ -233,19 +242,19 @@ readVariant(QDataStream &stream, Marker type) case MARKER_COUNT: default: Q_ASSERT(0); + case MARKER_EOF: return QVariant(); } } - - QVariantMap decodeUBJSONObject(QIODevice *io) { QDataStream stream(io); stream.setByteOrder(QDataStream::BigEndian); Marker marker = readMarker(stream); Q_ASSERT(marker == MARKER_OBJECT_BEGIN); + Q_UNUSED(marker); return readObject(stream); } |