sw/source/filter/ww8/wrtw8sty.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
New commits: commit 9d5005ac7bb27fb336bc4b593936fe2230b23eac Author: zhutyra <zhutyra> AuthorDate: Thu Feb 10 20:36:15 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Feb 11 17:00:36 2022 +0100 limit style export to words max style count LIBREOFFICE-U78X8I5G Change-Id: I436b4c13a4ce07f5e9e5d374163bc4de55cd2cde Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129803 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 3df6787eee11..f91375da04bb 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -151,9 +151,10 @@ 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_aFormatA.resize(nAlloc, nullptr); @@ -282,7 +283,7 @@ 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_aFormatA[ BuildGetSlot( *pFormat ) ] = pFormat; @@ -290,7 +291,7 @@ void MSWordStyles::BuildStylesTable() 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 ) ; @@ -307,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"))