src/lib/MSPUBCollector.cpp |   14 +++++++++++++-
 src/lib/MSPUBParser.cpp    |   11 +++++++++--
 src/lib/MSPUBParser2k.cpp  |    6 +++++-
 src/lib/MSPUBParser2k.h    |    2 ++
 src/lib/MSPUBParser97.cpp  |    2 ++
 5 files changed, 31 insertions(+), 4 deletions(-)

New commits:
commit 3b813e4fe5d9b6cd602998df536aa9b285cebf73
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 18 19:38:36 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Nov 18 19:38:36 2026 +0000

    skip a pub97 text span that ends before the current position
    
    Span ends are read from the file and need not increase. A lower one
    moved the position back, so the next span copied the same text again.
    
    since:
    
    commit a72381a447f242f7dc6c173541d563da82f018b1
    Date:   Wed Aug 1 20:55:42 2012 -0700
    
        pub97 basic text (still buggy)
    
    Change-Id: I3596fb82f8c74013a56cc42f8c35f08fa94d0aba

diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp
index f3aa8ae..2750ee3 100644
--- a/src/lib/MSPUBParser97.cpp
+++ b/src/lib/MSPUBParser97.cpp
@@ -112,6 +112,8 @@ void 
MSPUBParser97::parseContentsTextIfNecessary(librevenge::RVNGInputStream *in
           --iSpanEnd;
           spanEnd = paraEnd;
         }
+        if (spanEnd < currentSpanIndex)
+          continue;
         const CharacterStyle &spanStyle = spanInfo.m_style;
         std::vector<unsigned char> spanChars;
         spanChars.reserve(std::min(spanEnd - currentSpanIndex, m_length));
commit ce0b08bf958add589e02992dff35fc11d3d971e6
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 18 19:38:01 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Nov 18 19:38:01 2026 +0000

    check complex FOPT property arrays fit within their record
    
    The length came from the array's own header, entry size times entry
    count, so one shape could take the data that follows its record as its
    vertices or gradient.
    
    Stop reading complex properties at an array that does not fit in the
    rest of the record.
    
    since:
    
    commit 29932342358ce002d05886b43be41199952da9d0
    Date:   Fri Jul 27 19:48:45 2012 -0700
    
        start parsing binary vertices and segments
    
    Change-Id: Ic4db4101ea0ff34fa8a5f2e37f46bc9f11ee96f2

diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index e1981bd..e0f9357 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -2444,7 +2444,10 @@ FOPTValues 
MSPUBParser::extractFOPTValues(librevenge::RVNGInputStream *input, co
       entryLength = 4;
     }
     input->seek(-6, librevenge::RVNG_SEEK_CUR);
-    readNBytes(input, static_cast<unsigned long>(entryLength) * numEntries + 
6, ret.m_complexValues[id]);
+    const unsigned long complexLength = static_cast<unsigned 
long>(entryLength) * numEntries + 6;
+    if (complexLength > record.contentsOffset + record.contentsLength - 
input->tell())
+      break;
+    readNBytes(input, complexLength, ret.m_complexValues[id]);
   }
   return ret;
 }
commit c86b0e68472ffcc68ffb7a4feb93bf38d72222d0
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 18 19:37:16 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Nov 18 19:37:21 2026 +0000

    only draw border art if each side holds at most 4096 images
    
    The count of images per side is the side length divided by the line
    width, which comes from the file and can be tiny. Otherwise fall back
    to an ordinary stroke, which also keeps the double to unsigned
    conversions of the counts in range.
    
    since:
    
    commit 66b55a8e71b057435ab1521ed3f3d52158ca55d5
    Date:   Sat Aug 4 16:53:59 2012 -0700
    
        Emulate border art
    
    Change-Id: I0cd82321069bbd436b7d79138842ff8f79c005e6

diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index 0adb1fd..27d4537 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -197,6 +197,18 @@ void createTableLayout(const std::vector<CellInfo> &cells, 
TableLayout &tableLay
   }
 }
 
+const double MAX_BORDER_ART_IMAGES_PER_SIDE = 4096;
+
+bool hasDrawableBorderArt(const Coordinate &coord, unsigned 
borderImageWidthInEmu)
+{
+  if (borderImageWidthInEmu == 0)
+    return false;
+  const double maxSideLength = MAX_BORDER_ART_IMAGES_PER_SIDE * 
borderImageWidthInEmu / EMUS_IN_INCH;
+  const double width = coord.getWidthIn();
+  const double height = coord.getHeightIn();
+  return width >= 0 && width <= maxSideLength && height >= 0 && height <= 
maxSideLength;
+}
+
 typedef std::vector<std::pair<unsigned, unsigned> > ParagraphToCellMap_t;
 typedef std::vector<librevenge::RVNGString> SpanTexts_t;
 typedef std::vector<SpanTexts_t> ParagraphTexts_t;
@@ -833,7 +845,7 @@ std::function<void(void)> MSPUBCollector::paintShape(const 
ShapeInfo &info, cons
   const std::vector<Line> &lines = info.m_lines;
   if (hasStroke)
   {
-    if (hasBorderArt && lines[0].m_widthInEmu > 0)
+    if (hasBorderArt && hasDrawableBorderArt(coord, lines[0].m_widthInEmu))
     {
       bool stretch = info.m_stretchBorderArt;
       double x = coord.getXIn(m_width);
commit 89f3d24ee04e4841b4d7c17cd514ec138ec23454
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 18 19:36:17 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Nov 18 19:36:17 2026 +0000

    don't seek back before what a nested shape group already read
    
    A nested Escher container's length is not limited to its group, so the
    seek to the end of a nested group could land before bytes it had already
    read, and the parent group then read them again. With groups nested in
    pairs that doubled the work at each pair.
    
    since:
    
    commit dff36c7b1fa514beff551818a29ee93a886d2ae5
    Date:   Tue Jul 3 04:05:28 2012 -0700
    
        pub2k2: Independence Day miracle: nested groups finally working
    
    Change-Id: Ied671a7f06838ddec84affa0c11be14c24a07bdf

diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index 9c5c22a..e1981bd 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1673,7 +1673,11 @@ void 
MSPUBParser::parseShapeGroup(librevenge::RVNGInputStream *input, const Esch
       parseEscherShape(input, shapeOrGroup, parentCoordinateSystem, 
parentGroupAbsoluteCoord);
       break;
     }
-    input->seek(shapeOrGroup.contentsOffset + shapeOrGroup.contentsLength + 
getEscherElementTailLength(shapeOrGroup.type), librevenge::RVNG_SEEK_SET);
+    unsigned long next = shapeOrGroup.contentsOffset + 
shapeOrGroup.contentsLength + getEscherElementTailLength(shapeOrGroup.type);
+    // A nested container may claim more than its group holds, and its 
contents are read once.
+    if (shapeOrGroup.type == OFFICE_ART_SPGR_CONTAINER)
+      next = std::max(next, static_cast<unsigned long>(input->tell()));
+    input->seek(next, librevenge::RVNG_SEEK_SET);
   }
 }
 
commit 32d6904670519ac83d6bfaf771bc9bd7306bc023
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 18 19:35:31 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Nov 18 19:35:31 2026 +0000

    pub2k: read the children of a group id only once
    
    Chunk ids come from the file and need not be unique, so several group
    chunks can share an id, and each of them walked every chunk with that
    parent id. Nested groups that share ids at each level then multiplied
    the work level by level.
    
    since:
    
    commit 4ddc0f8ca51447e790c8d2c1ff468a6a2df90002
    Date:   Tue Jul 17 12:53:51 2012 -0700
    
        pub2k: handle shape groups
    
    Change-Id: I880fe031116f394723ef62c59befba69989a4a80

diff --git a/src/lib/MSPUBParser2k.cpp b/src/lib/MSPUBParser2k.cpp
index 3db3e0d..6680619 100644
--- a/src/lib/MSPUBParser2k.cpp
+++ b/src/lib/MSPUBParser2k.cpp
@@ -56,7 +56,8 @@ MSPUBParser2k::MSPUBParser2k(librevenge::RVNGInputStream 
*input, MSPUBCollector
     m_imageDataChunkIndices(),
     m_quillColorEntries(),
     m_chunkChildIndicesById(),
-    m_chunksBeingRead()
+    m_chunksBeingRead(),
+    m_expandedGroups()
 {
 }
 
@@ -599,6 +600,9 @@ void 
MSPUBParser2k::parseShapeFill(librevenge::RVNGInputStream *input, unsigned
 
 bool MSPUBParser2k::parseGroup(librevenge::RVNGInputStream *input, unsigned 
seqNum, unsigned page)
 {
+  // Chunk ids need not be unique, so the children of a group id are read once.
+  if (!m_expandedGroups.insert(seqNum).second)
+    return true;
   bool retVal = true;
   m_collector->beginGroup();
   m_collector->setCurrentGroupSeqNum(seqNum);
diff --git a/src/lib/MSPUBParser2k.h b/src/lib/MSPUBParser2k.h
index 28e9686..54bc80e 100644
--- a/src/lib/MSPUBParser2k.h
+++ b/src/lib/MSPUBParser2k.h
@@ -13,6 +13,7 @@
 #include <deque>
 #include <vector>
 #include <map>
+#include <set>
 
 #include "MSPUBParser.h"
 #include "ShapeType.h"
@@ -27,6 +28,7 @@ class MSPUBParser2k : public MSPUBParser
   std::vector<unsigned> m_quillColorEntries;
   std::map<unsigned, std::vector<unsigned> > m_chunkChildIndicesById;
   std::deque<unsigned> m_chunksBeingRead;
+  std::set<unsigned> m_expandedGroups;
 
 protected:
   // helper functions

Reply via email to