sc/source/filter/html/htmlpars.cxx |   42 ++++++++++++++++++++++++-----------
 sw/source/core/docnode/ndtbl.cxx   |   44 ++++++++++++++++++++++++++++++++++---
 2 files changed, 70 insertions(+), 16 deletions(-)

New commits:
commit f27b696f46e59c8168bea6c23c6bbb87e8ae64fb
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Mar 29 19:53:17 2024 +0000
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Apr 3 14:38:57 2024 +0200

    ofz#67708 ignore oversized colspans
    
    that can't fit in SCCOL
    
    ignore negative colspan and rowspans too
    
    Change-Id: I79a010bcd7d9d84de70f6dac2e09614d6d448227
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165480
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit b2c3ca63d28f7849d33d7a0c6436102fdbf6dbbb)

diff --git a/sc/source/filter/html/htmlpars.cxx 
b/sc/source/filter/html/htmlpars.cxx
index 1c230205e89b..063408b18e31 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -939,12 +939,20 @@ void ScHTMLLayoutParser::TableDataOn( HtmlImportInfo* 
pInfo )
         {
             case HtmlOptionId::COLSPAN:
             {
-                mxActEntry->nColOverlap = 
static_cast<SCCOL>(rOption.GetString().toInt32());
+                sal_Int32 nColOverlap = rOption.GetString().toInt32();
+                if (nColOverlap >= 0 && nColOverlap <= SCCOL_MAX)
+                    mxActEntry->nColOverlap = static_cast<SCCOL>(nColOverlap);
+                else
+                    SAL_WARN("sc", "ScHTMLLayoutParser::TableDataOn ignoring 
colspan: " << nColOverlap);
             }
             break;
             case HtmlOptionId::ROWSPAN:
             {
-                mxActEntry->nRowOverlap = 
static_cast<SCROW>(rOption.GetString().toInt32());
+                sal_Int32 nRowOverlap = rOption.GetString().toInt32();
+                if (nRowOverlap >= 0)
+                    mxActEntry->nRowOverlap = static_cast<SCROW>(nRowOverlap);
+                else
+                    SAL_WARN("sc", "ScHTMLLayoutParser::TableDataOn ignoring 
rowspan: " << nRowOverlap);
             }
             break;
             case HtmlOptionId::ALIGN:
commit fea111e56804ec761152af31fd083fb79b194cdf
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Mar 28 09:09:00 2024 +0000
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Apr 3 14:38:51 2024 +0200

    ofz: negative column offset
    
    Change-Id: Ieeb06e5c5d28f1c457db369a732bc37a7d5f2be8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165419
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 3f8c81f3f9ba1e27c97894c73e8802e5fdecf94b)

diff --git a/sc/source/filter/html/htmlpars.cxx 
b/sc/source/filter/html/htmlpars.cxx
index 8abe9a4e95d9..1c230205e89b 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -737,6 +737,11 @@ void ScHTMLLayoutParser::SetWidths()
                 OSL_ENSURE( nCol < nColsPerRow, 
"ScHTMLLayoutParser::SetWidths: column overflow" );
                 if (nCol >= nColsPerRow)
                     continue;
+                if (nCol < 0)
+                {
+                    SAL_WARN("sc", "negative offset: " << nCol);
+                    continue;
+                }
                 pE->nOffset = pOffsets[nCol];
                 nCol = nCol + pE->nColOverlap;
                 if ( nCol > nColsPerRow )
commit a47e278f36579926f341657db1d846416de61ba4
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sat Mar 23 15:40:26 2024 +0000
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Apr 3 14:38:43 2024 +0200

    ofz#67540 negative offset
    
    Change-Id: I498985962feb7d77c1a71af7002a85aa02aa3e65
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165189
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit d2210a5b418e7cbdef9a0de0fe3d9fd91115eb49)

diff --git a/sc/source/filter/html/htmlpars.cxx 
b/sc/source/filter/html/htmlpars.cxx
index 34f481eba09c..8abe9a4e95d9 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -731,19 +731,22 @@ void ScHTMLLayoutParser::SetWidths()
             for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < 
nListSize; ++i )
             {
                 auto& pE = maList[ i ];
-                if ( pE->nTab == nTable )
+                if (pE->nTab != nTable)
+                    continue;
+                nCol = pE->nCol - nColCntStart;
+                OSL_ENSURE( nCol < nColsPerRow, 
"ScHTMLLayoutParser::SetWidths: column overflow" );
+                if (nCol >= nColsPerRow)
+                    continue;
+                pE->nOffset = pOffsets[nCol];
+                nCol = nCol + pE->nColOverlap;
+                if ( nCol > nColsPerRow )
+                    nCol = nColsPerRow;
+                if (nCol < 0)
                 {
-                    nCol = pE->nCol - nColCntStart;
-                    OSL_ENSURE( nCol < nColsPerRow, 
"ScHTMLLayoutParser::SetWidths: column overflow" );
-                    if ( nCol < nColsPerRow )
-                    {
-                        pE->nOffset = pOffsets[nCol];
-                        nCol = nCol + pE->nColOverlap;
-                        if ( nCol > nColsPerRow )
-                            nCol = nColsPerRow;
-                        pE->nWidth = pOffsets[nCol] - pE->nOffset;
-                    }
+                    SAL_WARN("sc", "negative offset: " << nCol);
+                    continue;
                 }
+                pE->nWidth = pOffsets[nCol] - pE->nOffset;
             }
         }
     }
commit ef8d0a60de31fb0346ace1c682995bce0a7301d3
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Mar 22 14:27:01 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Apr 3 14:33:14 2024 +0200

    tdf#157241 sw: assert when importing ToX in table in rhbz589883-2.docx
    
    ndtbl.cxx:1417: SwNodes::TextToTable(): Assertion `!rNode.IsSectionNode()' 
failed.
    
    (regression from commit 62cb3b8b8d6106c6aeb073b12d84973a107182ef)
    
    Change-Id: Iec12282573cb914d1924f4da4a28e26e01b866df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165164
    Tested-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit df6fdb0041f8bfd251a4b03030b8bc47f0614c36)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165172
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 921abac0a5a0caa46875db640e3432379a5bcfa7)

diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 62ae90129297..690b3ade304a 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -1415,16 +1415,19 @@ SwTableNode* SwNodes::TextToTable( const 
SwNodes::TableRanges_t & rTableNodes,
     // delete frames of all contained content nodes
     for( nLines = 0; aNodeIndex <= rTableNodes.rbegin()->rbegin()->aEnd; 
++aNodeIndex,++nLines )
     {
-        SwNode& rNode = aNodeIndex.GetNode();
-        assert(!rNode.IsSectionNode()); // not possible in writerfilter import
-        if (rNode.IsTableNode())
+        SwNode* pNode(&aNodeIndex.GetNode());
+        while (pNode->IsSectionNode()) // could be ToX field in table
         {
-            lcl_RemoveBreaksTable(static_cast<SwTableNode&>(rNode),
+            pNode = pNode->GetNodes()[pNode->GetIndex()+1];
+        }
+        if (pNode->IsTableNode())
+        {
+            lcl_RemoveBreaksTable(static_cast<SwTableNode&>(*pNode),
                     (0 == nLines) ? pTableFormat : nullptr);
         }
-        else if (rNode.IsContentNode())
+        else if (pNode->IsContentNode())
         {
-            lcl_RemoveBreaks(static_cast<SwContentNode&>(rNode),
+            lcl_RemoveBreaks(static_cast<SwContentNode&>(*pNode),
                     (0 == nLines) ? pTableFormat : nullptr);
         }
     }
commit af27d5f7b5007ee39775ef0ad4c8c3548f44f369
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Mar 13 18:57:21 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Apr 3 14:33:14 2024 +0200

    tdf#157241 sw: fix crash on RTF paste or insert of nested tables
    
    The problem is that there are tables with only empty cell frames in the
    layout, which causes a crash in IsAllHiddenCell() added in commit
    ab7893544dc6be6dc192dffefd57cd5ddd421c35.
    
    This happens because first inner tables are created, with layout frames
    because the layout already exists.
    
    Then when SwNodes::TextToTable() is called for the outer table, it
    deletes the SwTextFrames, but not the SwTabFrames/SwCellFrames, so they
    remain uselessly in the layout.
    
    Delete these too, they will be recreated when the frame for the outer
    table is created.
    
    Also the transfer of any existing break to the outer table was missing.
    
    Change-Id: Idc2bc1d4c6572702510ae4355e4015c42770eb3e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164788
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 62cb3b8b8d6106c6aeb073b12d84973a107182ef)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164814
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 56676a8cb6899f376d9893392700e096ad589bed)

diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 71874cd24a0d..62ae90129297 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -880,6 +880,35 @@ const SwTable* SwDoc::TextToTable( const 
SwInsertTableOptions& rInsTableOpts,
     return &rNdTable;
 }
 
+static void lcl_RemoveBreaksTable(SwTableNode & rNode, SwTableFormat *const 
pTableFormat)
+{
+    // delete old layout frames, new ones need to be created...
+    rNode.DelFrames(nullptr);
+
+    // remove PageBreaks/PageDesc/ColBreak
+    SwFrameFormat & rFormat(*rNode.GetTable().GetFrameFormat());
+
+    const SfxPoolItem* pItem;
+    if (SfxItemState::SET == rFormat.GetItemState(RES_BREAK, false, &pItem))
+    {
+        if (pTableFormat)
+        {
+            pTableFormat->SetFormatAttr(*pItem);
+        }
+        rFormat.ResetFormatAttr(RES_BREAK);
+    }
+
+    if (SfxItemState::SET == rFormat.GetItemState(RES_PAGEDESC, false, &pItem)
+        && static_cast<SwFormatPageDesc const*>(pItem)->GetPageDesc())
+    {
+        if (pTableFormat)
+        {
+            pTableFormat->SetFormatAttr(*pItem);
+        }
+        rFormat.ResetFormatAttr(RES_PAGEDESC);
+    }
+}
+
 static void lcl_RemoveBreaks(SwContentNode & rNode, SwTableFormat *const 
pTableFormat)
 {
     // delete old layout frames, new ones need to be created...
@@ -1387,7 +1416,13 @@ SwTableNode* SwNodes::TextToTable( const 
SwNodes::TableRanges_t & rTableNodes,
     for( nLines = 0; aNodeIndex <= rTableNodes.rbegin()->rbegin()->aEnd; 
++aNodeIndex,++nLines )
     {
         SwNode& rNode = aNodeIndex.GetNode();
-        if( rNode.IsContentNode() )
+        assert(!rNode.IsSectionNode()); // not possible in writerfilter import
+        if (rNode.IsTableNode())
+        {
+            lcl_RemoveBreaksTable(static_cast<SwTableNode&>(rNode),
+                    (0 == nLines) ? pTableFormat : nullptr);
+        }
+        else if (rNode.IsContentNode())
         {
             lcl_RemoveBreaks(static_cast<SwContentNode&>(rNode),
                     (0 == nLines) ? pTableFormat : nullptr);

Reply via email to