libreoffice/SOURCES/0003-Related-rhbz-1618703-Properly-handle-failure-encodin.patch
2021-09-09 20:49:05 +00:00

285 lines
9.8 KiB
Diff

From 7d7089282e764d5c8481602fb2067c619882e45e Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <sbergman@redhat.com>
Date: Thu, 23 Aug 2018 18:10:01 +0200
Subject: [PATCH 3/5] Related rhbz#1618703: Properly handle failure encoding MS
file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
...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)
Conflicts:
sw/source/filter/ww8/wrtww8.cxx
Change-Id: I1123136ce1a25e181a0a27486954621a2dd095ea
---
sw/source/filter/ww8/docxexport.cxx | 4 ++-
sw/source/filter/ww8/docxexport.hxx | 2 +-
sw/source/filter/ww8/rtfexport.cxx | 4 ++-
sw/source/filter/ww8/rtfexport.hxx | 2 +-
sw/source/filter/ww8/wrtww8.cxx | 42 +++++++++++++++++++++--------
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 477422bee989..0b40a58df2bf 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -490,7 +490,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 );
@@ -530,6 +530,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 b553ba3f2601..8b42290594ae 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 12a8ef8b6f89..66e4448191ba 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3110,7 +3110,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();
@@ -3121,14 +3121,17 @@ namespace
{
std::size_t nBS = (nLen - nI > WW_BLOCKSIZE) ? WW_BLOCKSIZE : nLen - nI;
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;
@@ -3195,7 +3198,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();
@@ -3208,6 +3211,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 )
@@ -3262,7 +3267,7 @@ bool SwWW8Writer::InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec
return ( aEncryptionData.getLength() != 0 );
}
-void WW8Export::ExportDocument_Impl()
+ErrCode WW8Export::ExportDocument_Impl()
{
PrepareStorage();
@@ -3360,6 +3365,7 @@ void WW8Export::ExportDocument_Impl()
StoreDoc1();
+ ErrCode err = ERRCODE_NONE;
if ( bEncrypt )
{
SvStream *pStrmTemp, *pTableStrmTemp, *pDataStrmTemp;
@@ -3367,10 +3373,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.
@@ -3388,7 +3401,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.
@@ -3398,6 +3414,7 @@ void WW8Export::ExportDocument_Impl()
pStrmTemp->Seek( 0 );
pFib->WriteHeader( *pStrmTemp );
+ done:;
}
DELETEZ( m_pGrf );
@@ -3438,6 +3455,8 @@ void WW8Export::ExportDocument_Impl()
pDataStrm = nullptr;
GetWriter().GetStorage().Remove(SL::aData);
}
+
+ return err;
}
void WW8Export::PrepareStorage()
@@ -3517,16 +3536,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 7195677f4688..56bea59191d6 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 );
@@ -985,7 +985,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();
--
2.17.1