From feb1afc78290433b0c22b1b3f6d65542eeb5b957 Mon Sep 17 00:00:00 2001 From: Nikita Krupenko Date: Fri, 13 Jun 2014 20:04:16 +0300 Subject: Added stream version into network cache file format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment, there is no stream information in the cache file. This can lead to a problem when current stream version differs from version cache file written with. As an example, if file written with Qt 5.1.1, QTimeDate in the metadata stored as 13-bytes value, but Qt 5.2 and later can read additional 4 bytes which breaks following data, leading to network request just hangs forever. Adding stream version fixes this problem. As cache format changed, cache version bumped. Task-number: QTBUG-36219 Change-Id: I467d8c9fda82bcf9302192f51e7a00d2f6a9ff66 Reviewed-by: Jędrzej Nowacki --- src/network/access/qnetworkdiskcache.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/network/access/qnetworkdiskcache.cpp') diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index a1cbd9364e..86a3b20a9c 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -56,7 +56,7 @@ #define CACHE_POSTFIX QLatin1String(".d") #define PREPARED_SLASH QLatin1String("prepared/") -#define CACHE_VERSION 7 +#define CACHE_VERSION 8 #define DATA_DIR QLatin1String("data") #define MAX_COMPRESSION_SIZE (1024 * 1024 * 3) @@ -686,6 +686,7 @@ void QCacheItem::writeHeader(QFile *device) const out << qint32(CacheMagic); out << qint32(CurrentCacheVersion); + out << static_cast(out.version()); out << metaData; bool compressed = canCompress(); out << compressed; @@ -719,6 +720,13 @@ bool QCacheItem::read(QFile *device, bool readData) if (v != CurrentCacheVersion) return false; + qint32 streamVersion; + in >> streamVersion; + // Default stream version is also the highest we can handle + if (streamVersion > in.version()) + return false; + in.setVersion(streamVersion); + bool compressed; QByteArray dataBA; in >> metaData; -- cgit v1.2.3