sw/qa/extras/ooxmlexport/data/tdf131203.docx             |binary
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx                |    8 +++++++
 writerfilter/source/dmapper/DomainMapperTableManager.cxx |   17 +++++++--------
 3 files changed, 17 insertions(+), 8 deletions(-)

New commits:
commit e17b4df3fe5441ca66e4203c725a578eb1797eb2
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Thu Jan 5 10:21:10 2023 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Jan 5 14:39:34 2023 +0000

    tdf#131203 DOCX import: fix lost table when w:tblGrid is missing
    
    Load tables in case of incomplete text table definition, i.e.
    missing w:tblGrid and its w:gridCol elements, like MSO does.
    
    Note: Apache POI, and maybe old MSO versions generated such DOCX documents.
    
    divide_by_zero() was thrown from 975884fbbc3f80a634258ee562037688a42027a9
    "ofz#7110 ensure join is called on std::exceptions as well as 
uno::Exception".
    
    See also commit 9279b0bb5397d0520b727ab0d271f328807c8749
    "writerfilter: avoid divide by zero" and
    commit 116cadb5d2582532c69677a2f8499e8e9b7b9b80
    "tdf#59274 DOCX import: fix tables with incomplete grid".
    
    Change-Id: I991807da13e22e551f81c3fb60580be7a9c0fb50
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145069
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf131203.docx 
b/sw/qa/extras/ooxmlexport/data/tdf131203.docx
new file mode 100644
index 000000000000..2fd0dcabded4
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf131203.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index d282675b07ad..f33013413a1c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -249,6 +249,14 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf131959)
     assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tbl/w:tblPr/w:tblInd", "w", "360");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf131203)
+{
+    loadAndSave("tdf131203.docx");
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // loading thrown divide_by_zero()
+    assertXPath(pXmlDoc, "//w:tbl", 2);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testFDO76597)
 {
     loadAndSave("fdo76597.docx");
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx 
b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index bc8b59642714..004f34971b6a 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -807,15 +807,16 @@ void DomainMapperTableManager::endOfRowAction()
                     nFullWidthRelative += nFixLastCellWidth - 
(*pCellWidths)[nWidthsBound];
             }
 
-            if (nFullWidthRelative == 0)
-                throw o3tl::divide_by_zero();
-
-            for (size_t i = 0; i < nWidthsBound; ++i)
+            // tdf#131203 handle missing w:tblGrid
+            if (nFullWidthRelative > 0)
             {
-                nSum += (*pCellWidths)[i];
-                pSeparators[nPos].Position = (nSum * 10000) / 
nFullWidthRelative; // Relative position
-                pSeparators[nPos].IsVisible = true;
-                nPos++;
+                for (size_t i = 0; i < nWidthsBound; ++i)
+                {
+                    nSum += (*pCellWidths)[i];
+                    pSeparators[nPos].Position = (nSum * 10000) / 
nFullWidthRelative; // Relative position
+                    pSeparators[nPos].IsVisible = true;
+                    nPos++;
+                }
             }
         }
 

Reply via email to