[Libreoffice-commits] .: Branch 'libreoffice-3-6' - 2 commits - shell/inc shell/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 27 07:49:44 PDT 2012


 shell/inc/internal/zipfile.hxx                  |    1 
 shell/source/win32/ooofilereader/basereader.cxx |    9 +++--
 shell/source/win32/zipfile/zipfile.cxx          |   38 ++++++++++--------------
 3 files changed, 23 insertions(+), 25 deletions(-)

New commits:
commit c828a2fe53b7dede97d9b3b69462db22fb496685
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Mon Aug 27 16:33:13 2012 +0200

    fdo#53592: Try not to crash on empty m_ZipContent
    
    Change-Id: I9bdc9997e260a75682177c8641695b60df0c81a6
    Signed-off-by: Andras Timar <atimar at suse.com>

diff --git a/shell/source/win32/ooofilereader/basereader.cxx b/shell/source/win32/ooofilereader/basereader.cxx
index f4f694e..754d37e 100644
--- a/shell/source/win32/ooofilereader/basereader.cxx
+++ b/shell/source/win32/ooofilereader/basereader.cxx
@@ -81,9 +81,12 @@ void CBaseReader::Initialize( const std::string& ContentName)
         if (m_ZipContent.empty())
             m_ZipFile.GetUncompressedContent( ContentName, m_ZipContent );
 
-        xml_parser parser;
-        parser.set_document_handler(this);  // pass current reader as reader to the sax parser
-        parser.parse(&m_ZipContent[0], m_ZipContent.size());
+        if (!m_ZipContent.empty())
+        {
+            xml_parser parser;
+            parser.set_document_handler(this);  // pass current reader as reader to the sax parser
+            parser.parse(&m_ZipContent[0], m_ZipContent.size());
+        }
     }
     catch(std::exception&
     #if OSL_DEBUG_LEVEL > 0
diff --git a/shell/source/win32/zipfile/zipfile.cxx b/shell/source/win32/zipfile/zipfile.cxx
index 13b319c..381e52c 100644
--- a/shell/source/win32/zipfile/zipfile.cxx
+++ b/shell/source/win32/zipfile/zipfile.cxx
@@ -261,6 +261,8 @@ static bool areHeadersConsistent(const LocalFileHeader &header, const CentralDir
 
 static bool findCentralDirectoryEnd(StreamInterface *stream)
 {
+    if (!stream)
+        return false;
     stream->sseek(0, SEEK_SET);
     try
     {
@@ -483,7 +485,7 @@ void ZipFile::GetUncompressedContent(
             ContentBuffer.clear();
             return;
         }
-		(void)inflateEnd(&strm);
+        (void)inflateEnd(&strm);
     }
 }
 
commit 93a65b34adb99baea96aa85b7854aec2cf071647
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Mon Aug 27 16:01:55 2012 +0200

    fdo#53533: don't seek to bogus offset
    
    Change-Id: I27d056bdb8329dce302f2737bad5c5dc55791e74
    Signed-off-by: Andras Timar <atimar at suse.com>

diff --git a/shell/inc/internal/zipfile.hxx b/shell/inc/internal/zipfile.hxx
index 24fba65..d39db00 100644
--- a/shell/inc/internal/zipfile.hxx
+++ b/shell/inc/internal/zipfile.hxx
@@ -163,7 +163,6 @@ private:
 private:
     StreamInterface *m_pStream;
     bool m_bShouldFree;
-    long m_iStartOffset;
 };
 
 #endif
diff --git a/shell/source/win32/zipfile/zipfile.cxx b/shell/source/win32/zipfile/zipfile.cxx
index 452c17a..13b319c 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;


More information about the Libreoffice-commits mailing list