Skip to content

Commit 80cd74a

Browse files
author
Qt Continuous Integration System
committed
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: Fix crash in QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd
2 parents 828ccd1 + d278a52 commit 80cd74a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/network/access/qhttpnetworkreply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ int QHttpNetworkReplyPrivate::gunzipBodyPartially(QByteArray &compressed, QByteA
442442

443443
void QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd()
444444
{
445-
inflateEnd(&inflateStrm);
446-
initInflate = false;
445+
if (initInflate) {
446+
inflateEnd(&inflateStrm);
447+
initInflate = false;
448+
}
447449
}
448450

449451
#endif

tests/auto/qnetworkreply/tst_qnetworkreply.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ private Q_SLOTS:
332332
void qtbug15311doubleContentLength();
333333

334334
void qtbug18232gzipContentLengthZero();
335+
void nb279420gzipNoContentLengthEmptyContentDisconnect();
335336

336337
void synchronousRequest_data();
337338
void synchronousRequest();
@@ -5307,6 +5308,28 @@ void tst_QNetworkReply::qtbug18232gzipContentLengthZero()
53075308
QCOMPARE(reply->readAll(), QByteArray());
53085309
}
53095310

5311+
// Reproduced a crash in QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd
5312+
// where zlib inflateEnd was called for uninitialized zlib stream
5313+
void tst_QNetworkReply::nb279420gzipNoContentLengthEmptyContentDisconnect()
5314+
{
5315+
// Response with no Content-Length in header and empty content
5316+
QByteArray response("HTTP/1.0 200 OK\r\nContent-Encoding: gzip\r\n\r\n");
5317+
MiniHttpServer server(response);
5318+
server.doClose = true;
5319+
5320+
QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
5321+
QNetworkReplyPtr reply = manager.get(request);
5322+
5323+
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
5324+
QTestEventLoop::instance().enterLoop(10);
5325+
QVERIFY(!QTestEventLoop::instance().timeout());
5326+
QVERIFY(reply->isFinished());
5327+
QCOMPARE(reply->error(), QNetworkReply::NoError);
5328+
QCOMPARE(reply->size(), qint64(0));
5329+
QVERIFY(!reply->header(QNetworkRequest::ContentLengthHeader).isValid());
5330+
QCOMPARE(reply->readAll(), QByteArray());
5331+
}
5332+
53105333
void tst_QNetworkReply::synchronousRequest_data()
53115334
{
53125335
QTest::addColumn<QUrl>("url");

0 commit comments

Comments
 (0)