fix infinite loop in findCentralDirectoryEnd WPXSvInputStreamImpl::seek returns -1 if it catches an exception --- libmwaw/src/lib/MWAWZipStream.cxx 2013-06-18 00:37:57.208657845 +0200 +++ libmwaw/src/lib/MWAWZipStream.cxx 2013-06-18 00:48:20.971665257 +0200 @@ -258,18 +258,20 @@ static bool findCentralDirectoryEnd(WPXInputStream *input) { - input->seek(0, WPX_SEEK_SET); + // seek returns -1 both on error and on seek to position post-the-end + int ret = input->seek(0, WPX_SEEK_SET); try { - while (!input->atEOS()) - input->seek(1024, WPX_SEEK_CUR); + while (-1 != ret && !input->atEOS()) + ret = input->seek(1024, WPX_SEEK_CUR); input->seek(-1024, WPX_SEEK_CUR); - while (!input->atEOS()) { + ret = 0; // perhaps it's smaller than 1024? + while (-1 != ret && !input->atEOS()) { unsigned signature = getInt(input); if (signature == CDIR_END_SIG) { input->seek(-4, WPX_SEEK_CUR); return true; } else - input->seek(-3, WPX_SEEK_CUR); + ret = input->seek(-3, WPX_SEEK_CUR); } } catch (...) { return false;