diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-08-23 18:10:01 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-08-25 20:35:39 +0200 |
commit | 5be8cbdb874621111cb157a98013e254de3b269c (patch) | |
tree | f3e7499ed4b66587854c4a051ef9c164880a8b5c /sw | |
parent | 24b3d08018b6350d5e60615eb375b337ab1b4f75 (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"
Change-Id: I1123136ce1a25e181a0a27486954621a2dd095ea
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>
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 | 42 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 6 |
6 files changed, 42 insertions, 18 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 6199cbf94acd..1e3f8b86b2b2 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -504,7 +504,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 ); @@ -544,6 +544,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 12813a33f507..1f9f188e6225 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 7c5e096ea5b3..4736c21ca2f7 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -674,7 +674,7 @@ void RtfExport::WritePageDescTable() m_pTableInfo = std::make_shared<ww8::WW8TableInfo>(); } -void RtfExport::ExportDocument_Impl() +ErrCode RtfExport::ExportDocument_Impl() { // Make the header Strm() @@ -945,6 +945,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 fd2c7a285e7b..a1255cac5a11 100644 --- a/sw/source/filter/ww8/rtfexport.hxx +++ b/sw/source/filter/ww8/rtfexport.hxx @@ -118,7 +118,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 c158514fdd2c..745907044b52 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3119,7 +3119,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(); @@ -3130,14 +3130,17 @@ namespace { 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; @@ -3204,7 +3207,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(); @@ -3217,6 +3220,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 ) @@ -3267,7 +3272,7 @@ bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec return ( aEncryptionData.getLength() != 0 ); } -void WW8Export::ExportDocument_Impl() +ErrCode WW8Export::ExportDocument_Impl() { PrepareStorage(); @@ -3365,6 +3370,7 @@ void WW8Export::ExportDocument_Impl() StoreDoc1(); + ErrCode err = ERRCODE_NONE; if ( bEncrypt ) { SvStream *pStrmTemp, *pTableStrmTemp, *pDataStrmTemp; @@ -3372,10 +3378,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. @@ -3393,7 +3406,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. @@ -3403,6 +3419,7 @@ void WW8Export::ExportDocument_Impl() pStrmTemp->Seek( 0 ); pFib->WriteHeader( *pStrmTemp ); + done:; } DELETEZ( m_pGrf ); @@ -3443,6 +3460,8 @@ void WW8Export::ExportDocument_Impl() pDataStrm = nullptr; GetWriter().GetStorage().Remove(SL::aData); } + + return err; } void WW8Export::PrepareStorage() @@ -3522,16 +3541,17 @@ ErrCode SwWW8Writer::WriteStorage() } // Do the actual export + ErrCode err = ERRCODE_NONE; { bool bDot = mpMedium->GetFilter()->GetName().endsWith("Vorlage"); WW8Export aExport(this, m_pDoc, m_pCurrentPam, m_pOrigPam, bDot); m_pExport = &aExport; - aExport.ExportDocument( m_bWriteAll ); + err = aExport.ExportDocument( m_bWriteAll ); m_pExport = nullptr; } ::EndProgress( m_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 1a7f9675976b..0345a8d1ac87 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -581,7 +581,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(); @@ -799,7 +799,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 nCurrentPos ); @@ -1000,7 +1000,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(); |