[Libreoffice-commits] .: Branch 'libreoffice-4-0' - 3 commits - sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Jan 3 18:33:33 PST 2013


 sc/source/filter/xml/xmlcelli.cxx |   15 ++++++++++++++-
 sc/source/filter/xml/xmlcoli.cxx  |    3 ++-
 sc/source/filter/xml/xmlrowi.cxx  |    8 ++++++++
 sc/source/filter/xml/xmlrowi.hxx  |    2 ++
 4 files changed, 26 insertions(+), 2 deletions(-)

New commits:
commit ec6b0cb9da208d520972b3f305ecd79fdddb9023
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jan 4 03:27:01 2013 +0100

    don't overflow SCCOL during repeated cell import, fdo#58539
    
    This is the fix for the third and last crash with gnome#627150
    
    Change-Id: Iaf8611500fdb485017814b35789332c6c89530c0

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 186cea8..d58b9f5 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -167,7 +167,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
                 nMatrixRows = static_cast<SCROW>(sValue.toInt32());
             break;
             case XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED:
-                nColsRepeated = static_cast<SCCOL>(std::max( sValue.toInt32(), static_cast<sal_Int32>(1) ));
+                nColsRepeated = static_cast<SCCOL>(std::min<sal_Int32>( MAXCOLCOUNT,
+                            std::max( sValue.toInt32(), static_cast<sal_Int32>(1) ) ));
             break;
             case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
                 nCellType = GetScImport().GetCellType(sValue);
commit 8c71d6855fec68d2c65627f5bd47d1156c656405
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jan 4 03:17:13 2013 +0100

    add some more safety checks for row and column import from ODS
    
    Change-Id: Ic714c65cfe93198c462ba55752223f4e60e5aad9

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 41bd60c..186cea8 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -833,6 +833,12 @@ void ScXMLTableRowCellContext::AddTextAndValueCells( const ScAddress& rCellPos,
     for (SCCOL i = 0; i < nColsRepeated; ++i)
     {
         rCurrentPos.SetCol( rCellPos.Col() + i );
+
+        // it makes no sense to import data after the last supported column
+        // fdo#58539 & gnome#627150
+        if(rCurrentPos.Col() > MAXCOL)
+            break;
+
         if (i > 0)
             rTables.AddColumn(false);
         if (!bIsEmpty)
@@ -840,6 +846,12 @@ void ScXMLTableRowCellContext::AddTextAndValueCells( const ScAddress& rCellPos,
             for (SCROW j = 0; j < nRepeatedRows; ++j)
             {
                 rCurrentPos.SetRow( rCellPos.Row() + j );
+
+                // it makes no sense to import data after last supported row
+                // fdo#58539 & gnome#627150
+                if(rCurrentPos.Row() > MAXROW)
+                    break;
+
                 if( (rCurrentPos.Col() == 0) && (j > 0) )
                 {
                     rTables.AddRow();
diff --git a/sc/source/filter/xml/xmlcoli.cxx b/sc/source/filter/xml/xmlcoli.cxx
index 688300e..ed89294 100644
--- a/sc/source/filter/xml/xmlcoli.cxx
+++ b/sc/source/filter/xml/xmlcoli.cxx
@@ -66,7 +66,8 @@ ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
         {
             case XML_TOK_TABLE_COL_ATTR_REPEATED:
                 {
-                    nColCount = sValue.toInt32();
+                    nColCount = std::max<sal_Int32>(sValue.toInt32(), 1);
+                    nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);
                 }
                 break;
             case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx
index 67d1f23..a4434e1 100644
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@ -83,6 +83,7 @@ ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
             case XML_TOK_TABLE_ROW_ATTR_REPEATED:
             {
                 nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
+                nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
             }
             break;
             case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
commit c12df14aedbfcd9bd2bfd6dcc1e18524322bb939
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jan 4 02:59:23 2013 +0100

    workaround problems with row import, fdo#58539
    
    This fixes another crash with gnome#627150
    
    Change-Id: Ibd259c77f8df04b52c9fee0699e0edd1ad30e94e

diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx
index ea58165..67d1f23 100644
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@ -97,6 +97,7 @@ ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
             break;*/
         }
     }
+    mnLastRow = GetScImport().GetTables().GetCurrentRow() + nRepeatedRows;
     GetScImport().GetTables().AddRow();
     GetScImport().GetTables().SetRowStyle(sCellStyleName);
 }
@@ -154,6 +155,12 @@ void ScXMLTableRowContext::EndElement()
     }
     SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
+    if(nCurrentRow != mnLastRow)
+    {
+        // this document is most likely invalid in some way
+        SAL_WARN("sc", "we did not generate enough rows in the cell import!!");
+        nCurrentRow = mnLastRow;
+    }
     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     if(xSheet.is())
     {
diff --git a/sc/source/filter/xml/xmlrowi.hxx b/sc/source/filter/xml/xmlrowi.hxx
index a900ff7..02c5255 100644
--- a/sc/source/filter/xml/xmlrowi.hxx
+++ b/sc/source/filter/xml/xmlrowi.hxx
@@ -29,6 +29,8 @@ class ScXMLTableRowContext : public SvXMLImportContext
     rtl::OUString sStyleName;
     rtl::OUString sVisibility;
     sal_Int32 nRepeatedRows;
+    sal_Int32 mnLastRow; // to workaround problems with the cell import, can be removed when the cell
+                        // always adds enough rows
     bool bHasCell;
 
     const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }


More information about the Libreoffice-commits mailing list