diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-08-23 18:10:01 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-08-29 11:19:38 +0200 |
commit | 72d45497ea9625f192f0a6646577ddb0b3ceac88 (patch) | |
tree | 439cdc53c00fdc198d987672508ec62406954d86 /sw | |
parent | 4bb9287c25cb2fbe183f874bd62c44a553490756 (diff) |
Related rhbz#1618703: Properly handle failure encoding MS file
...when e.g. FIPS mode makes EncryptRC4 (in sw/source/filter/ww8/wrtww8.cxx)
fail, but which hadn't been propagated out to SwWW8Writer::WriteStorage (in
sw/source/filter/ww8/wrtww8.cxx)
Reviewed-on: https://gerrit.libreoffice.org/59518
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
(cherry picked from commit 229340812f6e6cc8c868915055583f60c82a8cf3)
Conflicts:
sw/source/filter/ww8/docxexport.cxx
...plus cherry-pick of follow-up 8114f976b897c4717368146a49d5404ef970c77a
"coverity#1438527 Nesting level does not match indentation"
Reviewed-on: https://gerrit.libreoffice.org/59572
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 5be8cbdb874621111cb157a98013e254de3b269c)
Change-Id: I1123136ce1a25e181a0a27486954621a2dd095ea
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 44 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 6 |
6 files changed, 43 insertions, 19 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 17c77c4ae776..952561d31141 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -503,7 +503,7 @@ void DocxExport::OutputDML(uno::Reference<drawing::XShape> const & xShape) aExport.WriteShape(xShape); } -void DocxExport::ExportDocument_Impl() +ErrCode DocxExport::ExportDocument_Impl() { // Set the 'Track Revisions' flag in the settings structure m_aSettings.trackRevisions = bool( RedlineFlags::On & m_nOrigRedlineFlags ); @@ -543,6 +543,8 @@ void DocxExport::ExportDocument_Impl() m_pStyles = nullptr; delete m_pSections; m_pSections = nullptr; + + return ERRCODE_NONE; } void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum ) diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index 65cf02fe2a1d..22b5dca7934e 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -191,7 +191,7 @@ public: protected: /// Format-dependent part of the actual export. - virtual void ExportDocument_Impl() override; + virtual ErrCode ExportDocument_Impl() override; /// Output SwEndNode virtual void OutputEndNode( const SwEndNode& ) override; diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 586dd01f23bd..679b96ac9a77 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -660,7 +660,7 @@ void RtfExport::WritePageDescTable() m_pTableInfo = std::make_shared<ww8::WW8TableInfo>(); } -void RtfExport::ExportDocument_Impl() +ErrCode RtfExport::ExportDocument_Impl() { // Make the header Strm() @@ -931,6 +931,8 @@ void RtfExport::ExportDocument_Impl() WriteMainText(); Strm().WriteChar('}'); + + return ERRCODE_NONE; } void RtfExport::PrepareNewPageDesc(const SfxItemSet* pSet, const SwNode& rNd, diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx index 869a888e9b25..b470ef593f30 100644 --- a/sw/source/filter/ww8/rtfexport.hxx +++ b/sw/source/filter/ww8/rtfexport.hxx @@ -117,7 +117,7 @@ public: protected: /// Format-dependent part of the actual export. - void ExportDocument_Impl() override; + ErrCode ExportDocument_Impl() override; void SectionBreaksAndFrames(const SwTextNode& /*rNode*/) override {} diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 916975ebdd91..afef206af619 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3117,7 +3117,7 @@ namespace { const sal_uLong WW_BLOCKSIZE = 0x200; - void EncryptRC4(msfilter::MSCodec_Std97& rCtx, SvStream &rIn, SvStream &rOut) + ErrCode EncryptRC4(msfilter::MSCodec_Std97& rCtx, SvStream &rIn, SvStream &rOut) { rIn.Seek(STREAM_SEEK_TO_END); sal_uLong nLen = rIn.Tell(); @@ -3126,16 +3126,19 @@ namespace sal_uInt8 in[WW_BLOCKSIZE]; for (std::size_t nI = 0, nBlock = 0; nI < nLen; nI += WW_BLOCKSIZE, ++nBlock) { - std::size_t nBS = (nLen - nI > WW_BLOCKSIZE) ? WW_BLOCKSIZE : nLen - nI; + std::size_t nBS = std::min(nLen - nI, WW_BLOCKSIZE); nBS = rIn.ReadBytes(in, nBS); - rCtx.InitCipher(nBlock); + if (!rCtx.InitCipher(nBlock)) { + return ERRCODE_IO_NOTSUPPORTED; + } rCtx.Encode(in, nBS, in, nBS); rOut.WriteBytes(in, nBS); } + return ERRCODE_NONE; } } -void MSWordExportBase::ExportDocument( bool bWriteAll ) +ErrCode MSWordExportBase::ExportDocument( bool bWriteAll ) { m_nCharFormatStart = DEFAULT_STYLES_COUNT; m_nFormatCollStart = m_nCharFormatStart + m_pDoc->GetCharFormats()->size() - 1; @@ -3202,7 +3205,7 @@ void MSWordExportBase::ExportDocument( bool bWriteAll ) if ( m_pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) m_pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )->RecalcObjOrdNums(); - ExportDocument_Impl(); + ErrCode err = ExportDocument_Impl(); m_aFrames.clear(); @@ -3215,6 +3218,8 @@ void MSWordExportBase::ExportDocument( bool bWriteAll ) *m_pCurPam = *m_pOrigPam; m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags(m_nOrigRedlineFlags); + + return err; } bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec ) @@ -3269,7 +3274,7 @@ bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec return ( aEncryptionData.getLength() != 0 ); } -void WW8Export::ExportDocument_Impl() +ErrCode WW8Export::ExportDocument_Impl() { PrepareStorage(); @@ -3367,6 +3372,7 @@ void WW8Export::ExportDocument_Impl() StoreDoc1(); + ErrCode err = ERRCODE_NONE; if ( bEncrypt ) { SvStream *pStrmTemp, *pTableStrmTemp, *pDataStrmTemp; @@ -3374,10 +3380,17 @@ void WW8Export::ExportDocument_Impl() pTableStrmTemp = xTableStrm.get(); pDataStrmTemp = xDataStrm.get(); - if ( pDataStrmTemp && pDataStrmTemp != pStrmTemp) - EncryptRC4(aCtx, *pDataStrm, *pDataStrmTemp); + if ( pDataStrmTemp && pDataStrmTemp != pStrmTemp) { + err = EncryptRC4(aCtx, *pDataStrm, *pDataStrmTemp); + if (err != ERRCODE_NONE) { + goto done; + } + } - EncryptRC4(aCtx, *pTableStrm, *pTableStrmTemp); + err = EncryptRC4(aCtx, *pTableStrm, *pTableStrmTemp); + if (err != ERRCODE_NONE) { + goto done; + } // Write Unencrypted Header 52 bytes to the start of the table stream // EncryptionVersionInfo (4 bytes): A Version structure where Version.vMajor MUST be 0x0001, and Version.vMinor MUST be 0x0001. @@ -3395,7 +3408,10 @@ void WW8Export::ExportDocument_Impl() pTableStrmTemp->WriteBytes(pSaltData, 16); pTableStrmTemp->WriteBytes(pSaltDigest, 16); - EncryptRC4(aCtx, GetWriter().Strm(), *pStrmTemp); + err = EncryptRC4(aCtx, GetWriter().Strm(), *pStrmTemp); + if (err != ERRCODE_NONE) { + goto done; + } // Write Unencrypted Fib 68 bytes to the start of the workdocument stream pFib->m_fEncrypted = true; // fEncrypted indicates the document is encrypted. @@ -3405,6 +3421,7 @@ void WW8Export::ExportDocument_Impl() pStrmTemp->Seek( 0 ); pFib->WriteHeader( *pStrmTemp ); + done:; } DELETEZ( m_pGrf ); @@ -3445,6 +3462,8 @@ void WW8Export::ExportDocument_Impl() pDataStrm = nullptr; GetWriter().GetStorage().Remove(SL::aData); } + + return err; } void WW8Export::PrepareStorage() @@ -3524,16 +3543,17 @@ ErrCode SwWW8Writer::WriteStorage() } // Do the actual export + ErrCode err = ERRCODE_NONE; { bool bDot = mpMedium->GetFilter()->GetName().endsWith("Vorlage"); WW8Export aExport(this, pDoc, pCurPam, pOrigPam, bDot); m_pExport = &aExport; - aExport.ExportDocument( bWriteAll ); + err = aExport.ExportDocument( bWriteAll ); m_pExport = nullptr; } ::EndProgress( pDoc->GetDocShell() ); - return ERRCODE_NONE; + return err; } ErrCode SwWW8Writer::WriteMedium( SfxMedium& ) diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index c4587e2552aa..ae8d71bd5231 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -574,7 +574,7 @@ public: public: /// The main function to export the document. - void ExportDocument( bool bWriteAll ); + ErrCode ExportDocument( bool bWriteAll ); /// Iterate through the nodes and call the appropriate OutputNode() on them. void WriteText(); @@ -788,7 +788,7 @@ public: protected: /// Format-dependent part of the actual export. - virtual void ExportDocument_Impl() = 0; + virtual ErrCode ExportDocument_Impl() = 0; /// Get the next position in the text node to output sal_Int32 GetNextPos( SwWW8AttrIter const * pAttrIter, const SwTextNode& rNode, sal_Int32 nAktPos ); @@ -989,7 +989,7 @@ public: virtual bool AddSectionBreaksForTOX() const override { return false; } private: /// Format-dependent part of the actual export. - virtual void ExportDocument_Impl() override; + virtual ErrCode ExportDocument_Impl() override; void PrepareStorage(); void WriteFkpPlcUsw(); |