sw/source/filter/ww8/wrtw8sty.cxx |   28 ++++++++++++++--------------
 sw/source/filter/ww8/wrtww8.hxx   |    4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

New commits:
commit 1a2f1b25e6d228dd586706584cf1c1f1d1ff069f
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Feb 10 10:53:27 2022 +0000
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Feb 11 14:32:55 2022 +0100

    limit style export to words max style count
    
    and
    
    use std::vector
    
    LIBREOFFICE-U78X8I5G
    
    Change-Id: I436b4c13a4ce07f5e9e5d374163bc4de55cd2cde
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129804
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index 72c171bacdff..9f103627d576 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -151,13 +151,13 @@ MSWordStyles::MSWordStyles( MSWordExportBase& rExport, 
bool bListStyles )
         m_rExport.m_rDoc.GetFootnoteInfo().GetAnchorCharFormat( 
m_rExport.m_rDoc );
         m_rExport.m_rDoc.GetFootnoteInfo().GetCharFormat( m_rExport.m_rDoc );
     }
-    sal_uInt16 nAlloc = WW8_RESERVED_SLOTS + 
m_rExport.m_rDoc.GetCharFormats()->size() - 1 +
+    sal_uInt32 nAlloc = WW8_RESERVED_SLOTS + 
m_rExport.m_rDoc.GetCharFormats()->size() - 1 +
                                          
m_rExport.m_rDoc.GetTextFormatColls()->size() - 1 +
                                          (bListStyles ? 
m_rExport.m_rDoc.GetNumRuleTable().size() - 1 : 0);
+    nAlloc = std::min<sal_uInt32>(nAlloc, MSWORD_MAX_STYLES_LIMIT);
 
     // somewhat generous ( free for up to 15 )
-    m_pFormatA.reset( new SwFormat*[ nAlloc ] );
-    memset( m_pFormatA.get(), 0, nAlloc * sizeof( SwFormat* ) );
+    m_aFormatA.resize(nAlloc, nullptr);
     memset( m_aHeadingParagraphStyles, -1 , MAXLEVEL * sizeof( sal_uInt16));
 
     BuildStylesTable();
@@ -173,7 +173,7 @@ sal_uInt16 MSWordStyles::GetSlot( const SwFormat* pFormat ) 
const
 {
     sal_uInt16 n;
     for ( n = 0; n < m_nUsedSlots; n++ )
-        if ( m_pFormatA[n] == pFormat )
+        if ( m_aFormatA[n] == pFormat )
             return n;
     return 0xfff;                   // 0xfff: WW: zero
 }
@@ -283,19 +283,19 @@ void MSWordStyles::BuildStylesTable()
 
     const SwCharFormats& rArr = *m_rExport.m_rDoc.GetCharFormats();       // 
first CharFormat
     // the default character style ( 0 ) will not be outputted !
-    for( size_t n = 1; n < rArr.size(); n++ )
+    for( size_t n = 1; n < rArr.size() && m_nUsedSlots < 
MSWORD_MAX_STYLES_LIMIT; n++ )
     {
         SwCharFormat* pFormat = rArr[n];
-        m_pFormatA[ BuildGetSlot( *pFormat ) ] = pFormat;
+        m_aFormatA[ BuildGetSlot( *pFormat ) ] = pFormat;
     }
 
     const SwTextFormatColls& rArr2 = *m_rExport.m_rDoc.GetTextFormatColls();   
// then TextFormatColls
     // the default character style ( 0 ) will not be outputted !
-    for( size_t n = 1; n < rArr2.size(); n++ )
+    for( size_t n = 1; n < rArr2.size() && m_nUsedSlots < 
MSWORD_MAX_STYLES_LIMIT; n++ )
     {
         SwTextFormatColl* pFormat = rArr2[n];
         sal_uInt16 nId = BuildGetSlot( *pFormat ) ;
-        m_pFormatA[ nId ] = pFormat;
+        m_aFormatA[ nId ] = pFormat;
         if ( pFormat->IsAssignedToListLevelOfOutlineStyle() )
         {
             int nLvl = pFormat->GetAssignedOutlineStyleLevel() ;
@@ -308,7 +308,7 @@ void MSWordStyles::BuildStylesTable()
         return;
 
     const SwNumRuleTable& rNumRuleTable = m_rExport.m_rDoc.GetNumRuleTable();
-    for (size_t i = 0; i < rNumRuleTable.size(); ++i)
+    for (size_t i = 0; i < rNumRuleTable.size() && m_nUsedSlots < 
MSWORD_MAX_STYLES_LIMIT; ++i)
     {
         const SwNumRule* pNumRule = rNumRuleTable[i];
         if (pNumRule->IsAutoRule() || pNumRule->GetName().startsWith("WWNum"))
@@ -348,8 +348,8 @@ void MSWordStyles::BuildStyleIds()
     for (sal_uInt16 n = 1; n < m_nUsedSlots; ++n)
     {
         OUString aName;
-        if(m_pFormatA[n])
-            aName = m_pFormatA[n]->GetName();
+        if (m_aFormatA[n])
+            aName = m_aFormatA[n]->GetName();
         else if (m_aNumRules.find(n) != m_aNumRules.end())
             aName = m_aNumRules[n]->GetName();
 
@@ -628,8 +628,8 @@ void MSWordStyles::OutputStyle( SwFormat* pFormat, 
sal_uInt16 nPos )
             for ( int nSuffix = 0; ; ++nSuffix ) {
                 bool clash=false;
                 for ( sal_uInt16 n = 1; n < m_nUsedSlots; ++n )
-                    if ( m_pFormatA[n] &&
-                         m_pFormatA[n]->GetName().equalsIgnoreAsciiCase(aName) 
)
+                    if ( m_aFormatA[n] &&
+                         m_aFormatA[n]->GetName().equalsIgnoreAsciiCase(aName) 
)
                     {
                         clash = true;
                         break;
@@ -718,7 +718,7 @@ void MSWordStyles::OutputStylesTable()
         if (m_aNumRules.find(n) != m_aNumRules.end())
             OutputStyle(m_aNumRules[n], n);
         else
-            OutputStyle( m_pFormatA[n], n );
+            OutputStyle(m_aFormatA[n], n);
     }
 
     m_rExport.AttrOutput().EndStyles( m_nUsedSlots );
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 72e5a8d65e1e..ef10e2a9a384 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1571,7 +1571,7 @@ class MSWordStyles
 {
     MSWordExportBase& m_rExport;
     sal_uInt16 m_aHeadingParagraphStyles[MAXLEVEL];
-    std::unique_ptr<SwFormat*[]> m_pFormatA; ///< Slot <-> Character and 
paragraph style array (0 for list styles).
+    std::vector<SwFormat*> m_aFormatA; ///< Slot <-> Character and paragraph 
style array (0 for list styles).
     sal_uInt16 m_nUsedSlots;
     bool m_bListStyles; ///< If list styles are requested to be exported as 
well.
     std::map<sal_uInt16, const SwNumRule*> m_aNumRules; ///< Slot <-> List 
style map.
@@ -1622,7 +1622,7 @@ public:
     /// Get styleId of the nId-th style (nId is its position in pFormatA).
     OString const & GetStyleId(sal_uInt16 nId) const;
 
-    const SwFormat* GetSwFormat(sal_uInt16 nId) const { return 
m_pFormatA[nId]; }
+    const SwFormat* GetSwFormat(sal_uInt16 nId) const { return 
m_aFormatA[nId]; }
     /// Get numbering rule of the nId-th style
     const SwNumRule* GetSwNumRule(sal_uInt16 nId) const;
     sal_uInt16 GetHeadingParagraphStyleId(sal_uInt16 nLevel) const { return 
m_aHeadingParagraphStyles[ nLevel ]; }

Reply via email to