From d3300205918f87054c9dd399ac53ad1e979dcdc7 Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Mon, 27 Aug 2012 16:01:55 +0200 Subject: fdo#53533: don't seek to bogus offset Change-Id: I27d056bdb8329dce302f2737bad5c5dc55791e74 --- shell/source/win32/zipfile/zipfile.cxx | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'shell/source') diff --git a/shell/source/win32/zipfile/zipfile.cxx b/shell/source/win32/zipfile/zipfile.cxx index 452c17a3d83e..13b319cc749c 100644 --- a/shell/source/win32/zipfile/zipfile.cxx +++ b/shell/source/win32/zipfile/zipfile.cxx @@ -259,9 +259,9 @@ static bool areHeadersConsistent(const LocalFileHeader &header, const CentralDir return true; } -static bool findCentralDirectoryEnd(StreamInterface *stream, long &startOffset) +static bool findCentralDirectoryEnd(StreamInterface *stream) { - stream->sseek(startOffset, SEEK_SET); + stream->sseek(0, SEEK_SET); try { while (stream->stell() != -1) @@ -270,7 +270,6 @@ static bool findCentralDirectoryEnd(StreamInterface *stream, long &startOffset) if (signature == CDIR_END_SIG) { stream->sseek(-4, SEEK_CUR); - startOffset = stream->stell(); return true; } else @@ -284,9 +283,9 @@ static bool findCentralDirectoryEnd(StreamInterface *stream, long &startOffset) return false; } -static bool isZipStream(StreamInterface *stream, long &startOffset) +static bool isZipStream(StreamInterface *stream) { - if (!findCentralDirectoryEnd(stream, startOffset)) + if (!findCentralDirectoryEnd(stream)) return false; CentralDirectoryEnd end; if (!readCentralDirectoryEnd(stream, end)) @@ -387,11 +386,10 @@ bool ZipFile::IsValidZipFileVersionNumber(void* /* stream*/) */ ZipFile::ZipFile(const std::string &FileName) : m_pStream(0), - m_bShouldFree(true), - m_iStartOffset(0) + m_bShouldFree(true) { m_pStream = new FileStream(FileName.c_str()); - if (m_pStream && !isZipStream(m_pStream, m_iStartOffset)) + if (m_pStream && !isZipStream(m_pStream)) { delete m_pStream; m_pStream = 0; @@ -400,10 +398,9 @@ ZipFile::ZipFile(const std::string &FileName) : ZipFile::ZipFile(StreamInterface *stream) : m_pStream(stream), - m_bShouldFree(false), - m_iStartOffset(0) + m_bShouldFree(false) { - if (!isZipStream(stream, m_iStartOffset)) + if (!isZipStream(stream)) m_pStream = 0; } @@ -424,15 +421,14 @@ ZipFile::~ZipFile() void ZipFile::GetUncompressedContent( const std::string &ContentName, /*inout*/ ZipContentBuffer_t &ContentBuffer) { - long startOffset = m_iStartOffset; - if (!findCentralDirectoryEnd(m_pStream, startOffset)) + if (!findCentralDirectoryEnd(m_pStream)) return; CentralDirectoryEnd end; if (!readCentralDirectoryEnd(m_pStream, end)) return; m_pStream->sseek(end.cdir_offset, SEEK_SET); CentralDirectoryEntry entry; - while (m_pStream->stell() != -1 && m_pStream->stell() < startOffset && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) + while (m_pStream->stell() != -1 && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) { if (!readCentralDirectoryEntry(m_pStream, entry)) return; @@ -497,15 +493,14 @@ void ZipFile::GetUncompressedContent( ZipFile::DirectoryPtr_t ZipFile::GetDirectory() const { DirectoryPtr_t dir(new Directory_t()); - long startOffset = m_iStartOffset; - if (!findCentralDirectoryEnd(m_pStream, startOffset)) + if (!findCentralDirectoryEnd(m_pStream)) return dir; CentralDirectoryEnd end; if (!readCentralDirectoryEnd(m_pStream, end)) return dir; m_pStream->sseek(end.cdir_offset, SEEK_SET); CentralDirectoryEntry entry; - while (m_pStream->stell() != -1 && m_pStream->stell() < startOffset && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) + while (m_pStream->stell() != -1 && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) { if (!readCentralDirectoryEntry(m_pStream, entry)) return dir; @@ -537,15 +532,14 @@ bool ZipFile::HasContent(const std::string &ContentName) const long ZipFile::GetFileLongestFileNameLength() const { long lmax = 0; - long startOffset = m_iStartOffset; - if (!findCentralDirectoryEnd(m_pStream, startOffset)) + if (!findCentralDirectoryEnd(m_pStream)) return lmax; CentralDirectoryEnd end; if (!readCentralDirectoryEnd(m_pStream, end)) return lmax; m_pStream->sseek(end.cdir_offset, SEEK_SET); CentralDirectoryEntry entry; - while (m_pStream->stell() != -1 && m_pStream->stell() < startOffset && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) + while (m_pStream->stell() != -1 && (unsigned long)m_pStream->stell() < end.cdir_offset + end.cdir_size) { if (!readCentralDirectoryEntry(m_pStream, entry)) return lmax; -- cgit v1.2.3