summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorumeshkadam <umesh.kadam@synerzip.com>2014-03-11 20:42:31 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-03-17 09:57:41 +0100
commit881ca9d48fc67665559484901ce6a670dc331ab8 (patch)
treea76d4ed3357d33959647c43ac8118e1c1ba2a925
parent030a9bfd42184c868bcc61b91af58f70b1c02677 (diff)
FDO#76013 : If original file has image whose link is broken RT gets corrupted.
- The original file contains an image which has invalid link. - since the link is invalid the import throws an exception while loading the image & the link is lost. - while exporting the system used to write an empty image for an unhandled graphic type, which is incorrect and the RT file would result in corrupt. - Fixed this issue and added UT. Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Reviewed on: https://gerrit.libreoffice.org/8549 Change-Id: If884f154d1fba921280d63930e7fccb979ea5608
-rw-r--r--oox/source/export/drawingml.cxx7
-rw-r--r--sw/qa/extras/ooxmlexport/data/FileWithInvalidImageLink.docxbin0 -> 15118 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx13
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx16
4 files changed, 31 insertions, 5 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index aeeff2587362..7d8ea84f3c3c 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -779,7 +779,12 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia )
pExtension = ".emf";
} else {
OSL_TRACE( "unhandled graphic type" );
- break;
+ /*Earlier, even in case of unhandled graphic types we were
+ proceeding to write the image, which would eventually
+ write an empty image with a zero size, and return a valid
+ relationID, which is incorrect.
+ */
+ return sRelId;
}
aData = aStream.GetData();
diff --git a/sw/qa/extras/ooxmlexport/data/FileWithInvalidImageLink.docx b/sw/qa/extras/ooxmlexport/data/FileWithInvalidImageLink.docx
new file mode 100644
index 000000000000..6ad5cac388ea
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/FileWithInvalidImageLink.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 9a43735a7b61..2a2f7c837315 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -2791,6 +2791,19 @@ DECLARE_OOXMLEXPORT_TEST(testFdo76016, "fdo76016.docx")
assertXPath(pXmlDoc, "//a:graphic/a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", "name", "adj2");
}
+DECLARE_OOXMLEXPORT_TEST(testFileWithInvalidImageLink, "FileWithInvalidImageLink.docx")
+{
+ /* In case if the original file has an image whose link is
+ invalid, then the RT file used to result in corruption
+ since the exported image would be an empty image.
+ */
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+ if (!pXmlDoc)
+ return;
+
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/pic:pic[1]/pic:blipFill[1]/a:blip[1]", "embed", "");
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index a380dd0c5272..cfa3b472911a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3319,9 +3319,6 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
nImageType = XML_embed;
}
- if ( aRelId.isEmpty() )
- return;
-
m_rExport.SdrExporter().startDMLAnchorInline(pFrmFmt, rSize);
// picture description (used for pic:cNvPr later too)
@@ -3383,7 +3380,18 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
// the actual picture
m_pSerializer->startElementNS( XML_pic, XML_blipFill,
FSEND );
- m_pSerializer->singleElementNS( XML_a, XML_blip,
+
+/* At this point we are certain that, WriteImage returns empty RelId
+ for unhandled graphic type. Therefore we write the picture description
+ and not the relation( coz there ain't any), so that the user knows
+ there is a image/graphic in the doc but it is broken instead of
+ completely discarding it.
+*/
+ if ( aRelId.isEmpty() )
+ m_pSerializer->singleElementNS( XML_a, XML_blip,
+ FSEND );
+ else
+ m_pSerializer->singleElementNS( XML_a, XML_blip,
FSNS( XML_r, nImageType ), aRelId.getStr(),
FSEND );