From ab7939145a83884ba618440db9d887b272d48bbe Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Wed, 10 Mar 2010 12:30:09 +0100 Subject: Avoid asserting when index passed to QZipReader::entryInfoAt is out of boundaries Reviewed-by: Benjamin Poulain --- src/gui/text/qzip.cpp | 4 +++- tests/auto/qzip/tst_qzip.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp index 5aa0a94..e2e0fb6 100644 --- a/src/gui/text/qzip.cpp +++ b/src/gui/text/qzip.cpp @@ -809,6 +809,7 @@ int QZipReader::count() const /*! Returns a FileInfo of an entry in the zipfile. The \a index is the index into the directoy listing of the zipfile. + Returns an invalid FileInfo if \a index is out of boundaries. \sa fileInfoList() */ @@ -816,7 +817,8 @@ QZipReader::FileInfo QZipReader::entryInfoAt(int index) const { d->scanFiles(); QZipReader::FileInfo fi; - d->fillFileInfo(index, fi); + if (index >= 0 && index < d->fileHeaders.count()) + d->fillFileInfo(index, fi); return fi; } diff --git a/tests/auto/qzip/tst_qzip.cpp b/tests/auto/qzip/tst_qzip.cpp index 99379b5..f586f5e 100644 --- a/tests/auto/qzip/tst_qzip.cpp +++ b/tests/auto/qzip/tst_qzip.cpp @@ -97,6 +97,9 @@ void tst_QZip::basicUnpack() | QFile::ReadUser | QFile::WriteUser )); QCOMPARE(zip.fileData("test/test.txt"), QByteArray("content\n")); + + fi = files.at(-1); + QVERIFY(!fi.isValid()); } void tst_QZip::symlinks() -- cgit v0.12