Kaydet (Commit) 1fc9923b authored tarafından Tushar Bende's avatar Tushar Bende Kaydeden (comit) Miklos Vajna

fdo#78469 FileCorrupt:During export LO was adding wrong tags inside <w:sdtPr>

Description :
Docx file corrupt after roundtrip.
Root cause: For some documents During export LO was not checking for the content of sdt and Even if sdt contains Drawing object
LO was writing text data related tags <w:text/> & <w:dataBinding> in <w:sdtPr>,This was the reason for corruption.

To Fix this checking is there is any Drawing Object in run if yes skip writing <w:dataBinding> tag in <w:sdtPr>
And if sdt content is Text and Drawing both do not write <Text> or <Picture> as these tags will again result in corruption.

Presently, while writing the sdtContent tag LO does not check for the content type due to which LO ends up adding the dataBinding along with the
Drawing/AlternateContent which is incorrect according ecma ECMA-376, Second Edition, Part 1 : 17.5.2.6. This cause in file corruption.

Added a check to restrict the aforementioned.

Reviewed on:
	https://gerrit.libreoffice.org/9371

Change-Id: Id31437db0309b0a2159389a4a9a1f5e13c1ac3a5
üst c07b8ded
...@@ -3408,6 +3408,16 @@ DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx") ...@@ -3408,6 +3408,16 @@ DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx")
assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" ); assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" );
} }
DECLARE_OOXMLEXPORT_TEST(testfdo78469, "fdo78469.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/header1.xml");
if (!pXmlDoc)
return;
// make sure dataBinding & text tags not presernt in sdtcontent
assertXPath(pXmlDoc, "/w:hdr[1]/w:tbl[1]/w:tr[1]/w:tc[2]/w:p[1]/w:sdt[2]/w:sdtPr[1]/w:dataBinding[1]",0);
assertXPath(pXmlDoc, "/w:hdr[1]/w:tbl[1]/w:tr[1]/w:tc[2]/w:p[1]/w:sdt[2]/w:sdtPr[1]/w:text[1]",0);
}
DECLARE_OOXMLEXPORT_TEST(testfdo78300,"fdo78300.docx") DECLARE_OOXMLEXPORT_TEST(testfdo78300,"fdo78300.docx")
{ {
xmlDocPtr pXmlDoc = parseExport("word/document.xml"); xmlDocPtr pXmlDoc = parseExport("word/document.xml");
......
...@@ -372,6 +372,9 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT ...@@ -372,6 +372,9 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
m_pSerializer->endElementNS( XML_w, XML_p ); m_pSerializer->endElementNS( XML_w, XML_p );
WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs ); WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs );
//sdtcontent is written so Set m_bParagraphHasDrawing to false
m_rExport.SdrExporter().setParagraphHasDrawing( false );
m_bRunTextIsOn = false;
m_pSerializer->mergeTopMarks(); m_pSerializer->mergeTopMarks();
// Check for end of cell, rows, tables here // Check for end of cell, rows, tables here
...@@ -411,10 +414,10 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, ::sax_fastparse ...@@ -411,10 +414,10 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, ::sax_fastparse
m_pSerializer->singleElement( nSdtPrToken, m_pSerializer->singleElement( nSdtPrToken,
FSNS(XML_w, XML_val), OString::number( rand() ), FSNS(XML_w, XML_val), OString::number( rand() ),
FSEND ); FSEND );
else if( nSdtPrToken > 0 ) else if( (nSdtPrToken > 0) && !(m_bRunTextIsOn && m_rExport.SdrExporter().IsParagraphHasDrawing()))
m_pSerializer->singleElement( nSdtPrToken, FSEND ); m_pSerializer->singleElement( nSdtPrToken, FSEND );
if( pSdtPrDataBindingAttrs ) if(( pSdtPrDataBindingAttrs ) && !m_rExport.SdrExporter().IsParagraphHasDrawing())
{ {
XFastAttributeListRef xAttrList( pSdtPrDataBindingAttrs ); XFastAttributeListRef xAttrList( pSdtPrDataBindingAttrs );
m_pSerializer->singleElementNS( XML_w, XML_dataBinding, xAttrList ); m_pSerializer->singleElementNS( XML_w, XML_dataBinding, xAttrList );
...@@ -1655,7 +1658,7 @@ void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCh ...@@ -1655,7 +1658,7 @@ void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCh
{ {
m_closeHyperlinkInPreviousRun = true; m_closeHyperlinkInPreviousRun = true;
} }
m_bRunTextIsOn = true;
// one text can be split into more <w:t>blah</w:t>'s by line breaks etc. // one text can be split into more <w:t>blah</w:t>'s by line breaks etc.
const sal_Unicode *pBegin = rText.getStr(); const sal_Unicode *pBegin = rText.getStr();
const sal_Unicode *pEnd = pBegin + rText.getLength(); const sal_Unicode *pEnd = pBegin + rText.getLength();
...@@ -7388,6 +7391,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri ...@@ -7388,6 +7391,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
m_pRedlineData( NULL ), m_pRedlineData( NULL ),
m_nRedlineId( 0 ), m_nRedlineId( 0 ),
m_bOpenedSectPr( false ), m_bOpenedSectPr( false ),
m_bRunTextIsOn( false ),
m_bWritingHeaderFooter( false ), m_bWritingHeaderFooter( false ),
m_sFieldBkm( ), m_sFieldBkm( ),
m_nNextBookmarkId( 0 ), m_nNextBookmarkId( 0 ),
......
...@@ -720,6 +720,9 @@ private: ...@@ -720,6 +720,9 @@ private:
/// Flag indicating that the section properties are being written /// Flag indicating that the section properties are being written
bool m_bOpenedSectPr; bool m_bOpenedSectPr;
/// Flag indicating that the Run Text is being written
bool m_bRunTextIsOn;
/// Flag indicating that the header \ footer are being written /// Flag indicating that the header \ footer are being written
bool m_bWritingHeaderFooter; bool m_bWritingHeaderFooter;
......
...@@ -145,6 +145,7 @@ struct DocxSdrExport::Impl ...@@ -145,6 +145,7 @@ struct DocxSdrExport::Impl
OStringBuffer m_aTextFrameStyle; OStringBuffer m_aTextFrameStyle;
bool m_bFrameBtLr; bool m_bFrameBtLr;
bool m_bDrawingOpen; bool m_bDrawingOpen;
bool m_bParagraphHasDrawing; ///Flag for checking drawing in a paragraph.
bool m_bFlyFrameGraphic; bool m_bFlyFrameGraphic;
sax_fastparser::FastAttributeList* m_pFlyFillAttrList; sax_fastparser::FastAttributeList* m_pFlyFillAttrList;
sax_fastparser::FastAttributeList* m_pFlyWrapAttrList; sax_fastparser::FastAttributeList* m_pFlyWrapAttrList;
...@@ -166,6 +167,7 @@ struct DocxSdrExport::Impl ...@@ -166,6 +167,7 @@ struct DocxSdrExport::Impl
m_pTextboxAttrList(0), m_pTextboxAttrList(0),
m_bFrameBtLr(false), m_bFrameBtLr(false),
m_bDrawingOpen(false), m_bDrawingOpen(false),
m_bParagraphHasDrawing(false),
m_bFlyFrameGraphic(false), m_bFlyFrameGraphic(false),
m_pFlyFillAttrList(0), m_pFlyFillAttrList(0),
m_pFlyWrapAttrList(0), m_pFlyWrapAttrList(0),
...@@ -248,6 +250,21 @@ bool DocxSdrExport::IsDrawingOpen() ...@@ -248,6 +250,21 @@ bool DocxSdrExport::IsDrawingOpen()
return m_pImpl->m_bDrawingOpen; return m_pImpl->m_bDrawingOpen;
} }
void DocxSdrExport::setDrawingOpen(bool bDrawingOpen)
{
m_pImpl->m_bDrawingOpen = bDrawingOpen;
}
bool DocxSdrExport::IsParagraphHasDrawing()
{
return m_pImpl->m_bParagraphHasDrawing;
}
void DocxSdrExport::setParagraphHasDrawing(bool bParagraphHasDrawing)
{
m_pImpl->m_bParagraphHasDrawing = bParagraphHasDrawing;
}
sax_fastparser::FastAttributeList*& DocxSdrExport::getFlyFillAttrList() sax_fastparser::FastAttributeList*& DocxSdrExport::getFlyFillAttrList()
{ {
return m_pImpl->m_pFlyFillAttrList; return m_pImpl->m_pFlyFillAttrList;
...@@ -276,6 +293,7 @@ void DocxSdrExport::setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrL ...@@ -276,6 +293,7 @@ void DocxSdrExport::setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrL
void DocxSdrExport::startDMLAnchorInline(const SwFrmFmt* pFrmFmt, const Size& rSize) void DocxSdrExport::startDMLAnchorInline(const SwFrmFmt* pFrmFmt, const Size& rSize)
{ {
m_pImpl->m_bDrawingOpen = true; m_pImpl->m_bDrawingOpen = true;
m_pImpl->m_bParagraphHasDrawing = true;
m_pImpl->m_pSerializer->startElementNS(XML_w, XML_drawing, FSEND); m_pImpl->m_pSerializer->startElementNS(XML_w, XML_drawing, FSEND);
const SvxLRSpaceItem pLRSpaceItem = pFrmFmt->GetLRSpace(false); const SvxLRSpaceItem pLRSpaceItem = pFrmFmt->GetLRSpace(false);
......
...@@ -65,6 +65,9 @@ public: ...@@ -65,6 +65,9 @@ public:
bool getFrameBtLr(); bool getFrameBtLr();
bool IsDrawingOpen(); bool IsDrawingOpen();
void setDrawingOpen(bool bDrawingOpen);
bool IsParagraphHasDrawing();
void setParagraphHasDrawing(bool bParagraphHasDrawing);
sax_fastparser::FastAttributeList*& getFlyFillAttrList(); sax_fastparser::FastAttributeList*& getFlyFillAttrList();
sax_fastparser::FastAttributeList* getFlyWrapAttrList(); sax_fastparser::FastAttributeList* getFlyWrapAttrList();
void setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrList); void setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment