[Libreoffice-commits] libmspub.git: 7 commits - configure.ac HACKING Makefile.am src/lib

David Tardon dtardon at redhat.com
Tue Jun 16 01:22:34 PDT 2015


 HACKING                    |    2 +-
 Makefile.am                |    2 ++
 configure.ac               |    1 +
 src/lib/MSPUBCollector.cpp |   14 +++++++-------
 src/lib/MSPUBParser.cpp    |   10 ++++++++--
 src/lib/MSPUBParser.h      |    1 +
 src/lib/MSPUBParser2k.cpp  |   11 +++++++----
 src/lib/MSPUBParser97.cpp  |    6 +++++-
 src/lib/libmspub_utils.cpp |   31 +++++++++++++++++++++++++++++++
 src/lib/libmspub_utils.h   |    2 ++
 10 files changed, 65 insertions(+), 15 deletions(-)

New commits:
commit 9f5a58d13f14717b8d7f366bb525bc91f01bd6b4
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 10:15:05 2015 +0200

    avoid out-of-bounds access
    
    Change-Id: I9e880dc3bdbf91f1d0d7bbca68d6188c6cc6da4e

diff --git a/src/lib/MSPUBParser2k.cpp b/src/lib/MSPUBParser2k.cpp
index a6ae02b..7003b72 100644
--- a/src/lib/MSPUBParser2k.cpp
+++ b/src/lib/MSPUBParser2k.cpp
@@ -564,12 +564,15 @@ bool MSPUBParser2k::parseGroup(librevenge::RVNGInputStream *input, unsigned seqN
   bool retVal = true;
   m_collector->beginGroup();
   m_collector->setCurrentGroupSeqNum(seqNum);
-  for (unsigned i = 0; i < m_chunkChildIndicesById[seqNum].size(); ++i)
+  if (seqNum < m_chunkChildIndicesById.size())
   {
-    const ContentChunkReference &childChunk = m_contentChunks.at(m_chunkChildIndicesById[seqNum][i]);
-    if (childChunk.type == SHAPE || childChunk.type == GROUP)
+    for (unsigned i = 0; i < m_chunkChildIndicesById[seqNum].size(); ++i)
     {
-      retVal = retVal && parse2kShapeChunk(childChunk, input, page, false);
+      const ContentChunkReference &childChunk = m_contentChunks.at(m_chunkChildIndicesById[seqNum][i]);
+      if (childChunk.type == SHAPE || childChunk.type == GROUP)
+      {
+        retVal = retVal && parse2kShapeChunk(childChunk, input, page, false);
+      }
     }
   }
   m_collector->endGroup();
commit 1da6f0a9782dca04e902ab5115116d74a2941199
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:42:06 2015 +0200

    avoid excessive allocation
    
    Change-Id: Ia664a2d348022657376d5632d1fb087d656f2be2

diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp
index 2fb8d6d..2d717e1 100644
--- a/src/lib/MSPUBParser97.cpp
+++ b/src/lib/MSPUBParser97.cpp
@@ -112,7 +112,7 @@ void MSPUBParser97::parseContentsTextIfNecessary(librevenge::RVNGInputStream *in
         }
         const CharacterStyle &spanStyle = spanInfo.m_style;
         std::vector<unsigned char> spanChars;
-        spanChars.reserve(spanEnd - currentSpanIndex);
+        spanChars.reserve(std::min(spanEnd - currentSpanIndex, m_length));
         for (unsigned i = currentSpanIndex; i < spanEnd; ++i)
         {
           unsigned char ch = textInfo.m_chars[i];
commit b3b438e4ab2536fdb65910c1ebee3d2a8c2a627c
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:26:45 2015 +0200

    avoid excessive allocation
    
    Change-Id: Ibb7eaaf77d5f80510de81de217f8cb63682d9dce

diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index bc6fef2..6b79243 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -11,6 +11,7 @@
 #include <set>
 #include <sstream>
 #include <string>
+#include <utility>
 #include <algorithm>
 #include <string.h>
 
@@ -1134,7 +1135,7 @@ void MSPUBParser::parseFonts(librevenge::RVNGInputStream *input, const QuillChun
 void MSPUBParser::parseDefaultStyle(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk)
 {
   readU32(input);
-  unsigned numElements = readU32(input);
+  unsigned numElements = std::min(readU32(input), m_length);
   input->seek(input->tell() + 12, librevenge::RVNG_SEEK_SET);
   std::vector<unsigned> offsets;
   offsets.reserve(numElements);
commit 998c647c9002cc2e364cf862f2ff4dab540e6649
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:38:15 2015 +0200

    avoid excessive allocation
    
    Change-Id: Ib136b3ad0bbdc75697dac0357a1afd17751cbbfd

diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp
index 67db0a7..2fb8d6d 100644
--- a/src/lib/MSPUBParser97.cpp
+++ b/src/lib/MSPUBParser97.cpp
@@ -238,6 +238,7 @@ CharacterStyle MSPUBParser97::readCharacterStyle(
 
 MSPUBParser97::TextInfo97 MSPUBParser97::getTextInfo(librevenge::RVNGInputStream *input, unsigned length)
 {
+  length = std::min(length, m_length); // sanity check
   std::vector<unsigned char> chars;
   chars.reserve(length);
   std::vector<unsigned> paragraphEnds;
commit 06e845f157abb9dd207652e6553cab4ec6cef92d
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:13:13 2015 +0200

    keep the stream size around
    
    Change-Id: Ib5e127b445233ea7b0c499afedd4295edfad33d2

diff --git a/configure.ac b/configure.ac
index 22aaac1..8c3883b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,7 @@ AC_SUBST(ZLIB_LIBS)
 AC_CHECK_HEADERS(
 	boost/bind.hpp \
 	boost/function.hpp \
+	boost/numeric/conversion/cast.hpp \
 	boost/optional.hpp \
 	boost/ptr_container/ptr_vector.hpp \
 	boost/scoped_ptr.hpp \
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index b680f71..bc6fef2 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -13,6 +13,9 @@
 #include <string>
 #include <algorithm>
 #include <string.h>
+
+#include <boost/numeric/conversion/cast.hpp>
+
 #include <librevenge-stream/librevenge-stream.h>
 #include <zlib.h>
 
@@ -39,7 +42,9 @@ namespace libmspub
 {
 
 MSPUBParser::MSPUBParser(librevenge::RVNGInputStream *input, MSPUBCollector *collector)
-  : m_input(input), m_collector(collector),
+  : m_input(input),
+    m_length(boost::numeric_cast<unsigned>(getLength(input))),
+    m_collector(collector),
     m_blockInfo(), m_contentChunks(),
     m_cellsChunkIndices(),
     m_pageChunkIndices(), m_shapeChunkIndices(),
diff --git a/src/lib/MSPUBParser.h b/src/lib/MSPUBParser.h
index 54e41aa..b6145ce 100644
--- a/src/lib/MSPUBParser.h
+++ b/src/lib/MSPUBParser.h
@@ -144,6 +144,7 @@ protected:
   boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg, std::map<unsigned short, std::vector<unsigned char> > &foptVal);
 
   librevenge::RVNGInputStream *m_input;
+  unsigned m_length;
   MSPUBCollector *m_collector;
   std::vector<MSPUBBlockInfo> m_blockInfo;
   std::vector<ContentChunkReference> m_contentChunks;
diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp
index 29614ba..67db0a7 100644
--- a/src/lib/MSPUBParser97.cpp
+++ b/src/lib/MSPUBParser97.cpp
@@ -8,6 +8,9 @@
  */
 
 #include "MSPUBParser97.h"
+
+#include <utility>
+
 #include "MSPUBCollector.h"
 #include "libmspub_utils.h"
 #include "MSPUBTypes.h"
diff --git a/src/lib/libmspub_utils.cpp b/src/lib/libmspub_utils.cpp
index dd98762..71cfc21 100644
--- a/src/lib/libmspub_utils.cpp
+++ b/src/lib/libmspub_utils.cpp
@@ -337,6 +337,37 @@ void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::v
   return;
 }
 
+unsigned long getLength(librevenge::RVNGInputStream *const input)
+{
+  if (!input)
+    throw EndOfStreamException();
+
+  const long orig = input->tell();
+
+  unsigned long end = 0;
+
+  if (0 == input->seek(0, librevenge::RVNG_SEEK_END))
+  {
+    end = static_cast<unsigned long>(input->tell());
+  }
+  else
+  {
+    // RVNG_SEEK_END does not work. Use the harder way.
+    if (0 != input->seek(0, librevenge::RVNG_SEEK_SET))
+      throw EndOfStreamException();
+    while (!input->isEnd())
+    {
+      readU8(input);
+      ++end;
+    }
+  }
+
+  if (0 != input->seek(orig, librevenge::RVNG_SEEK_SET))
+    throw EndOfStreamException();
+
+  return end;
+}
+
 #define SURROGATE_VALUE(h,l) (((h) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000)
 
 
diff --git a/src/lib/libmspub_utils.h b/src/lib/libmspub_utils.h
index cadfbbf..c4051f1 100644
--- a/src/lib/libmspub_utils.h
+++ b/src/lib/libmspub_utils.h
@@ -85,6 +85,8 @@ double readFixedPoint(librevenge::RVNGInputStream *input);
 double toFixedPoint(int fp);
 void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
 
+unsigned long getLength(librevenge::RVNGInputStream *input);
+
 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, const char *encoding);
 
 bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
commit cb8deab6a1807a105bc9ef127a86c8c9047d4161
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:14:13 2015 +0200

    astyle
    
    Change-Id: I73cdd7f09452224698d8844ae2529e85daa8f980

diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index af6224f..76905dc 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -1006,13 +1006,13 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co
     if (isTable)
     {
       librevenge::RVNGPropertyListVector columnWidths;
-        for (unsigned col = 0; col < (get(info.m_tableInfo).m_columnWidthsInEmu.size()); ++col)
-        {
-      librevenge::RVNGPropertyList columnWidth;
-          columnWidth.insert("style:column-width", double(get(info.m_tableInfo).m_columnWidthsInEmu[col]) / EMUS_IN_INCH);
-          columnWidths.append(columnWidth);
-        }
-        props.insert("librevenge:table-columns", columnWidths);
+      for (unsigned col = 0; col < (get(info.m_tableInfo).m_columnWidthsInEmu.size()); ++col)
+      {
+        librevenge::RVNGPropertyList columnWidth;
+        columnWidth.insert("style:column-width", double(get(info.m_tableInfo).m_columnWidthsInEmu[col]) / EMUS_IN_INCH);
+        columnWidths.append(columnWidth);
+      }
+      props.insert("librevenge:table-columns", columnWidths);
 
       m_painter->startTableObject(props);
 
commit 1f8c762956ed1afc8021b2e0d92c0f54549e2299
Author: David Tardon <dtardon at redhat.com>
Date:   Tue Jun 16 09:13:53 2015 +0200

    add make astyle target
    
    Change-Id: I4b572644e1b802661bf40b8fbb2f6708ce9bb9d9

diff --git a/HACKING b/HACKING
index 4f02df4..5d8d713 100644
--- a/HACKING
+++ b/HACKING
@@ -3,6 +3,6 @@
 This project uses mostly the same file naming and coding style like
 libwpd and the rest of Fridrich's libraries. Please run
 
-    astyle --options=astyle.options \*.cpp \*.h
+    make astyle
 
 before committing.
diff --git a/Makefile.am b/Makefile.am
index 4952380..c631a5d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,3 +20,5 @@ distclean-local:
 dist-hook:
 	git log --date=short --pretty="format:@%cd  %an  <%ae>  [%H]%n%n%s%n%n%e%b" | sed -e "s|^\([^@]\)|\t\1|" -e "s|^@||" >$(distdir)/ChangeLog
 
+astyle:
+	astyle --options=astyle.options \*.cpp \*.h


More information about the Libreoffice-commits mailing list