kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0003-Related-rhbz-1618703-Properly-handle-failure-encodin.patch

55db36
From 7d7089282e764d5c8481602fb2067c619882e45e Mon Sep 17 00:00:00 2001
55db36
From: Stephan Bergmann <sbergman@redhat.com>
55db36
Date: Thu, 23 Aug 2018 18:10:01 +0200
55db36
Subject: [PATCH 3/5] Related rhbz#1618703: Properly handle failure encoding MS
55db36
 file
55db36
MIME-Version: 1.0
55db36
Content-Type: text/plain; charset=UTF-8
55db36
Content-Transfer-Encoding: 8bit
55db36
55db36
...when e.g. FIPS mode makes EncryptRC4 (in sw/source/filter/ww8/wrtww8.cxx)
55db36
fail, but which hadn't been propagated out to SwWW8Writer::WriteStorage (in
55db36
sw/source/filter/ww8/wrtww8.cxx)
55db36
55db36
Reviewed-on: https://gerrit.libreoffice.org/59518
55db36
Tested-by: Jenkins
55db36
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
55db36
(cherry picked from commit 229340812f6e6cc8c868915055583f60c82a8cf3)
55db36
Conflicts:
55db36
	sw/source/filter/ww8/docxexport.cxx
55db36
55db36
...plus cherry-pick of follow-up 8114f976b897c4717368146a49d5404ef970c77a
55db36
"coverity#1438527 Nesting level does not match indentation"
55db36
55db36
Reviewed-on: https://gerrit.libreoffice.org/59572
55db36
Tested-by: Jenkins
55db36
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
55db36
Tested-by: Caolán McNamara <caolanm@redhat.com>
55db36
55db36
(cherry picked from commit 5be8cbdb874621111cb157a98013e254de3b269c)
55db36
Conflicts:
55db36
	sw/source/filter/ww8/wrtww8.cxx
55db36
55db36
Change-Id: I1123136ce1a25e181a0a27486954621a2dd095ea
55db36
---
55db36
 sw/source/filter/ww8/docxexport.cxx |  4 ++-
55db36
 sw/source/filter/ww8/docxexport.hxx |  2 +-
55db36
 sw/source/filter/ww8/rtfexport.cxx  |  4 ++-
55db36
 sw/source/filter/ww8/rtfexport.hxx  |  2 +-
55db36
 sw/source/filter/ww8/wrtww8.cxx     | 42 +++++++++++++++++++++--------
55db36
 sw/source/filter/ww8/wrtww8.hxx     |  6 ++---
55db36
 6 files changed, 42 insertions(+), 18 deletions(-)
55db36
55db36
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
55db36
index 477422bee989..0b40a58df2bf 100644
55db36
--- a/sw/source/filter/ww8/docxexport.cxx
55db36
+++ b/sw/source/filter/ww8/docxexport.cxx
55db36
@@ -490,7 +490,7 @@ void DocxExport::OutputDML(uno::Reference<drawing::XShape> const & xShape)
55db36
     aExport.WriteShape(xShape);
55db36
 }
55db36
 
55db36
-void DocxExport::ExportDocument_Impl()
55db36
+ErrCode DocxExport::ExportDocument_Impl()
55db36
 {
55db36
     // Set the 'Track Revisions' flag in the settings structure
55db36
     m_aSettings.trackRevisions = bool( RedlineFlags::On & m_nOrigRedlineFlags );
55db36
@@ -530,6 +530,8 @@ void DocxExport::ExportDocument_Impl()
55db36
     m_pStyles = nullptr;
55db36
     delete m_pSections;
55db36
     m_pSections = nullptr;
55db36
+
55db36
+    return ERRCODE_NONE;
55db36
 }
55db36
 
55db36
 void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum )
55db36
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
55db36
index b553ba3f2601..8b42290594ae 100644
55db36
--- a/sw/source/filter/ww8/docxexport.hxx
55db36
+++ b/sw/source/filter/ww8/docxexport.hxx
55db36
@@ -191,7 +191,7 @@ public:
55db36
 
55db36
 protected:
55db36
     /// Format-dependent part of the actual export.
55db36
-    virtual void ExportDocument_Impl() override;
55db36
+    virtual ErrCode ExportDocument_Impl() override;
55db36
 
55db36
     /// Output SwEndNode
55db36
     virtual void OutputEndNode( const SwEndNode& ) override;
55db36
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
55db36
index 586dd01f23bd..679b96ac9a77 100644
55db36
--- a/sw/source/filter/ww8/rtfexport.cxx
55db36
+++ b/sw/source/filter/ww8/rtfexport.cxx
55db36
@@ -660,7 +660,7 @@ void RtfExport::WritePageDescTable()
55db36
     m_pTableInfo = std::make_shared<ww8::WW8TableInfo>();
55db36
 }
55db36
 
55db36
-void RtfExport::ExportDocument_Impl()
55db36
+ErrCode RtfExport::ExportDocument_Impl()
55db36
 {
55db36
     // Make the header
55db36
     Strm()
55db36
@@ -931,6 +931,8 @@ void RtfExport::ExportDocument_Impl()
55db36
     WriteMainText();
55db36
 
55db36
     Strm().WriteChar('}');
55db36
+
55db36
+    return ERRCODE_NONE;
55db36
 }
55db36
 
55db36
 void RtfExport::PrepareNewPageDesc(const SfxItemSet* pSet, const SwNode& rNd,
55db36
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
55db36
index 869a888e9b25..b470ef593f30 100644
55db36
--- a/sw/source/filter/ww8/rtfexport.hxx
55db36
+++ b/sw/source/filter/ww8/rtfexport.hxx
55db36
@@ -117,7 +117,7 @@ public:
55db36
 
55db36
 protected:
55db36
     /// Format-dependent part of the actual export.
55db36
-    void ExportDocument_Impl() override;
55db36
+    ErrCode ExportDocument_Impl() override;
55db36
 
55db36
     void SectionBreaksAndFrames(const SwTextNode& /*rNode*/) override {}
55db36
 
55db36
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
55db36
index 12a8ef8b6f89..66e4448191ba 100644
55db36
--- a/sw/source/filter/ww8/wrtww8.cxx
55db36
+++ b/sw/source/filter/ww8/wrtww8.cxx
55db36
@@ -3110,7 +3110,7 @@ namespace
55db36
 {
55db36
     const sal_uLong WW_BLOCKSIZE = 0x200;
55db36
 
55db36
-    void EncryptRC4(msfilter::MSCodec_Std97& rCtx, SvStream &rIn, SvStream &rOut)
55db36
+    ErrCode EncryptRC4(msfilter::MSCodec_Std97& rCtx, SvStream &rIn, SvStream &rOut)
55db36
     {
55db36
         rIn.Seek(STREAM_SEEK_TO_END);
55db36
         sal_uLong nLen = rIn.Tell();
55db36
@@ -3121,14 +3121,17 @@ namespace
55db36
         {
55db36
             std::size_t nBS = (nLen - nI > WW_BLOCKSIZE) ? WW_BLOCKSIZE : nLen - nI;
55db36
             nBS = rIn.ReadBytes(in, nBS);
55db36
-            rCtx.InitCipher(nBlock);
55db36
+            if (!rCtx.InitCipher(nBlock)) {
55db36
+                return ERRCODE_IO_NOTSUPPORTED;
55db36
+            }
55db36
             rCtx.Encode(in, nBS, in, nBS);
55db36
             rOut.WriteBytes(in, nBS);
55db36
         }
55db36
+        return ERRCODE_NONE;
55db36
     }
55db36
 }
55db36
 
55db36
-void MSWordExportBase::ExportDocument( bool bWriteAll )
55db36
+ErrCode MSWordExportBase::ExportDocument( bool bWriteAll )
55db36
 {
55db36
     m_nCharFormatStart = DEFAULT_STYLES_COUNT;
55db36
     m_nFormatCollStart = m_nCharFormatStart + m_pDoc->GetCharFormats()->size() - 1;
55db36
@@ -3195,7 +3198,7 @@ void MSWordExportBase::ExportDocument( bool bWriteAll )
55db36
     if ( m_pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
55db36
         m_pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )->RecalcObjOrdNums();
55db36
 
55db36
-    ExportDocument_Impl();
55db36
+    ErrCode err = ExportDocument_Impl();
55db36
 
55db36
     m_aFrames.clear();
55db36
 
55db36
@@ -3208,6 +3211,8 @@ void MSWordExportBase::ExportDocument( bool bWriteAll )
55db36
     *m_pCurPam = *m_pOrigPam;
55db36
 
55db36
     m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags(m_nOrigRedlineFlags);
55db36
+
55db36
+    return err;
55db36
 }
55db36
 
55db36
 bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec )
55db36
@@ -3262,7 +3267,7 @@ bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec
55db36
     return ( aEncryptionData.getLength() != 0 );
55db36
 }
55db36
 
55db36
-void WW8Export::ExportDocument_Impl()
55db36
+ErrCode WW8Export::ExportDocument_Impl()
55db36
 {
55db36
     PrepareStorage();
55db36
 
55db36
@@ -3360,6 +3365,7 @@ void WW8Export::ExportDocument_Impl()
55db36
 
55db36
     StoreDoc1();
55db36
 
55db36
+    ErrCode err = ERRCODE_NONE;
55db36
     if ( bEncrypt )
55db36
     {
55db36
         SvStream *pStrmTemp, *pTableStrmTemp, *pDataStrmTemp;
55db36
@@ -3367,10 +3373,17 @@ void WW8Export::ExportDocument_Impl()
55db36
         pTableStrmTemp = xTableStrm.get();
55db36
         pDataStrmTemp = xDataStrm.get();
55db36
 
55db36
-        if ( pDataStrmTemp && pDataStrmTemp != pStrmTemp)
55db36
-            EncryptRC4(aCtx, *pDataStrm, *pDataStrmTemp);
55db36
+        if ( pDataStrmTemp && pDataStrmTemp != pStrmTemp) {
55db36
+            err = EncryptRC4(aCtx, *pDataStrm, *pDataStrmTemp);
55db36
+            if (err != ERRCODE_NONE) {
55db36
+                goto done;
55db36
+            }
55db36
+        }
55db36
 
55db36
-        EncryptRC4(aCtx, *pTableStrm, *pTableStrmTemp);
55db36
+        err = EncryptRC4(aCtx, *pTableStrm, *pTableStrmTemp);
55db36
+        if (err != ERRCODE_NONE) {
55db36
+            goto done;
55db36
+        }
55db36
 
55db36
         // Write Unencrypted Header 52 bytes to the start of the table stream
55db36
         // EncryptionVersionInfo (4 bytes): A Version structure where Version.vMajor MUST be 0x0001, and Version.vMinor MUST be 0x0001.
55db36
@@ -3388,7 +3401,10 @@ void WW8Export::ExportDocument_Impl()
55db36
         pTableStrmTemp->WriteBytes(pSaltData, 16);
55db36
         pTableStrmTemp->WriteBytes(pSaltDigest, 16);
55db36
 
55db36
-        EncryptRC4(aCtx, GetWriter().Strm(), *pStrmTemp);
55db36
+        err = EncryptRC4(aCtx, GetWriter().Strm(), *pStrmTemp);
55db36
+        if (err != ERRCODE_NONE) {
55db36
+            goto done;
55db36
+        }
55db36
 
55db36
         // Write Unencrypted Fib 68 bytes to the start of the workdocument stream
55db36
         pFib->m_fEncrypted = true; // fEncrypted indicates the document is encrypted.
55db36
@@ -3398,6 +3414,7 @@ void WW8Export::ExportDocument_Impl()
55db36
 
55db36
         pStrmTemp->Seek( 0 );
55db36
         pFib->WriteHeader( *pStrmTemp );
55db36
+    done:;
55db36
     }
55db36
 
55db36
     DELETEZ( m_pGrf );
55db36
@@ -3438,6 +3455,8 @@ void WW8Export::ExportDocument_Impl()
55db36
         pDataStrm = nullptr;
55db36
         GetWriter().GetStorage().Remove(SL::aData);
55db36
     }
55db36
+
55db36
+    return err;
55db36
 }
55db36
 
55db36
 void WW8Export::PrepareStorage()
55db36
@@ -3517,16 +3536,17 @@ ErrCode SwWW8Writer::WriteStorage()
55db36
     }
55db36
 
55db36
     // Do the actual export
55db36
+    ErrCode err = ERRCODE_NONE;
55db36
     {
55db36
         bool bDot = mpMedium->GetFilter()->GetName().endsWith("Vorlage");
55db36
         WW8Export aExport(this, pDoc, pCurPam, pOrigPam, bDot);
55db36
         m_pExport = &aExport;
55db36
-        aExport.ExportDocument( bWriteAll );
55db36
+        err = aExport.ExportDocument( bWriteAll );
55db36
         m_pExport = nullptr;
55db36
     }
55db36
 
55db36
     ::EndProgress( pDoc->GetDocShell() );
55db36
-    return ERRCODE_NONE;
55db36
+    return err;
55db36
 }
55db36
 
55db36
 ErrCode SwWW8Writer::WriteMedium( SfxMedium& )
55db36
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
55db36
index 7195677f4688..56bea59191d6 100644
55db36
--- a/sw/source/filter/ww8/wrtww8.hxx
55db36
+++ b/sw/source/filter/ww8/wrtww8.hxx
55db36
@@ -574,7 +574,7 @@ public:
55db36
 
55db36
 public:
55db36
     /// The main function to export the document.
55db36
-    void ExportDocument( bool bWriteAll );
55db36
+    ErrCode ExportDocument( bool bWriteAll );
55db36
 
55db36
     /// Iterate through the nodes and call the appropriate OutputNode() on them.
55db36
     void WriteText();
55db36
@@ -788,7 +788,7 @@ public:
55db36
 
55db36
 protected:
55db36
     /// Format-dependent part of the actual export.
55db36
-    virtual void ExportDocument_Impl() = 0;
55db36
+    virtual ErrCode ExportDocument_Impl() = 0;
55db36
 
55db36
     /// Get the next position in the text node to output
55db36
     sal_Int32 GetNextPos( SwWW8AttrIter const * pAttrIter, const SwTextNode& rNode, sal_Int32 nAktPos );
55db36
@@ -985,7 +985,7 @@ public:
55db36
     virtual bool AddSectionBreaksForTOX() const override { return false; }
55db36
 private:
55db36
     /// Format-dependent part of the actual export.
55db36
-    virtual void ExportDocument_Impl() override;
55db36
+    virtual ErrCode ExportDocument_Impl() override;
55db36
 
55db36
     void PrepareStorage();
55db36
     void WriteFkpPlcUsw();
55db36
-- 
55db36
2.17.1
55db36