Add regression test for QTBUG-22660

QHttpNetworkReply crashed in Qt4.7 and 4.8 if a HTTP server responded with
gzip-encoded empty content without defining Content-Length in the response
header. This commit adds the test for the problem as a regression test to
Qt5.

Change-Id: Iddfb970a31d92a66fd1dd524811cf54bb06e5157
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
This commit is contained in:
Sami Rosendahl 2012-01-05 15:48:12 +02:00 committed by Qt by Nokia
parent d55cdcd59f
commit e6b9382ae2

View File

@ -369,6 +369,7 @@ private Q_SLOTS:
void qtbug15311doubleContentLength();
void qtbug18232gzipContentLengthZero();
void qtbug22660gzipNoContentLengthEmptyContent();
void synchronousRequest_data();
void synchronousRequest();
@ -6363,6 +6364,28 @@ void tst_QNetworkReply::qtbug18232gzipContentLengthZero()
QCOMPARE(reply->readAll(), QByteArray());
}
// Reproduced a crash in QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd
// where zlib inflateEnd was called for uninitialized zlib stream
void tst_QNetworkReply::qtbug22660gzipNoContentLengthEmptyContent()
{
// Response with no Content-Length in header and empty content
QByteArray response("HTTP/1.0 200 OK\r\nContent-Encoding: gzip\r\n\r\n");
MiniHttpServer server(response);
server.doClose = true;
QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
QNetworkReplyPtr reply = manager.get(request);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
QTestEventLoop::instance().enterLoop(10);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(reply->isFinished());
QCOMPARE(reply->error(), QNetworkReply::NoError);
QCOMPARE(reply->size(), qint64(0));
QVERIFY(!reply->header(QNetworkRequest::ContentLengthHeader).isValid());
QCOMPARE(reply->readAll(), QByteArray());
}
void tst_QNetworkReply::synchronousRequest_data()
{
QTest::addColumn<QUrl>("url");