Bug 164949 - Crash on Clone Formatting when selecting more than one table cell
Summary: Crash on Clone Formatting when selecting more than one table cell
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
25.2.0.1 rc
Hardware: All All
: highest critical
Assignee: Oliver Specht (CIB)
URL:
Whiteboard:
Keywords: bibisected, bisected, regression
Depends on:
Blocks: Clone-Formatting
  Show dependency treegraph
 
Reported: 2025-01-29 22:33 UTC by Octavio Alvarez
Modified: 2025-02-17 10:29 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
Screenshot right before crash (42.34 KB, image/png)
2025-01-29 22:36 UTC, Octavio Alvarez
Details
Backtrace (6.65 KB, text/plain)
2025-01-29 23:53 UTC, Octavio Alvarez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Octavio Alvarez 2025-01-29 22:33:48 UTC
Description:
Crash on Clone Formatting when selecting more than one table cell. Verified on locally in multiple platforms. When the whole cell is not selected or one cell is fully selected, no crash occurs.

Steps to Reproduce:
1. Start LibreOffice
2. Table > Insert Table... defaults will create a 2x2 table.
3. Select two or more cells.
4. Clone Formatting (via toolbar or context menu)

Actual Results:
Crash

Expected Results:
Formatting is cloned and cursor is changed to Clone Formatting.


Reproducible: Always


User Profile Reset: No

Additional Info:
I bibisected it to the following commit:
https://git.libreoffice.org/core/+/3e4aa127416a5947882e6644409468aa1ca039ae


Version: 25.2.0.3 (X86_64) / LibreOffice Community
Build ID: 520(Build:3)
CPU threads: 16; OS: Linux 6.12; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Debian package version: 4:25.2.0~rc3-2+b1
Calc: threaded
Comment 1 Octavio Alvarez 2025-01-29 22:36:21 UTC
Created attachment 198876 [details]
Screenshot right before crash
Comment 2 m_a_riosv 2025-01-29 22:44:19 UTC
Not reproducible with
Version: 25.2.0.3 (X86_64) / LibreOffice Community
Build ID: e1cf4a87eb02d755bce1a01209907ea5ddc8f069
CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded

Please test in safe mode, Menu/Help/Restart in Safe Mode
Comment 3 Octavio Alvarez 2025-01-29 22:53:27 UTC
Under Safe Mode (with reset profiles and all) it also crashes.
Comment 4 Octavio Alvarez 2025-01-29 23:07:41 UTC
Crash on master (25.8).

Version: 25.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 85c8901dc2710e91bccb64cd7d8068441f42f65b
CPU threads: 16; OS: Linux 6.12; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 5 Octavio Alvarez 2025-01-29 23:53:45 UTC
Created attachment 198877 [details]
Backtrace
Comment 6 Xisco Faulí 2025-01-30 00:09:05 UTC
Regression introduced by:

commit 3e4aa127416a5947882e6644409468aa1ca039ae	[log]
author	Oliver Specht <oliver.specht@cib.de>	Wed May 29 12:19:24 2024 +0200
committer	Thorsten Behrens <thorsten.behrens@allotropia.de>	Mon Jul 15 20:10:24 2024 +0200
tree a51dc11d70adb025b179a35c9653d6650b893357
parent b3922a8d0051a656228f80aeee5360692c9bba2e [diff]

tdf#122756 clone formatting includes table number format

Bisected with: bibisect-linux64-25.2
Comment 7 gmolleda 2025-02-07 14:41:43 UTC
Crash in Version: 25.2.1.0.0+ (X86_64) / LibreOffice Community
Build ID: 5a97854375383efe2c506647eeef2e4ef6cd9b73
CPU threads: 4; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: es-ES (es_ES.UTF-8); UI: es-ES
Calc: threaded
Comment 8 Octavio Alvarez 2025-02-13 15:27:53 UTC
In the commit causing the crash, the changed file is sw/source/uibase/uiview/formatclipboard.cxx.

In the backtrace, the crash occurs in an assert() in frame #5:

    SfxItemPool* pTarget(getTargetPool(nWhich));
    if (nullptr == pTarget)
        assert(!"unknown which - don't ask me for defaults");


#5  0x00007ffff32e58d5 in SfxItemPool::GetUserOrPoolDefaultItem(unsigned short) const (this=0x5555565c19e0, nWhich=10023) at /home/alvarezp/src/libreoffice/core/svl/source/items/itempool.cxx:725

#6  0x00007ffff33339ad in SfxItemSet::MergeItem_Impl(unsigned short, SfxPoolItem const*, bool) (this=0x55555b2b0050, nWhich=10023, pFnd2=0x0, bIgnoreDefaults=false) at /home/alvarezp/src/libreoffice/cor
e/svl/source/items/itemset.cxx:1167

#7  0x00007ffff3333c75 in SfxItemSet::MergeValues(SfxItemSet const&) (this=0x55555b2b0050, rSet=...) at /home/alvarezp/src/libreoffice/core/svl/source/items/itemset.cxx:1218

#8  0x00007fff99465804 in SwEditShell::GetTableBoxFormulaAttrs(SfxItemSet&) const (this=0x555556ddcb60, rSet=warning: RTTI symbol not found for class 'SfxItemSetFixed<(unsigned short)99, (unsigned short)100, (unsigned short)111, (unsigned short)113, (unsigned short)116, (unsigned short)116, (unsigned short)119, (unsigned short)119, (unsigned short)126, (unsigned short)126, (unsigned short)128, (unsigned short)128, (unsigned short)156, (unsigned short)156, (unsigned short)10023, (unsigned short)10025, (unsigned short)10368, (unsigned short)10453, (unsigned short)20588, (unsigned short)20588, (unsigned short)20592, (unsigned short)20592, (unsigned short)21150, (unsigned short)21150>'
...) at /home/alvarezp/src/libreoffice/core/sw/source/core/edit/edtab.cxx:334

#9  0x00007fff9a3a601f in (anonymous namespace)::lcl_getTableAttributes(SfxItemSet&, SwWrtShell&, bool) (rSet=warning: RTTI symbol not found for class 'SfxItemSetFixed<(unsigned short)99, (unsigned short)100, (unsigned short)111, (unsigned short)113, (unsigned short)116, (unsigned short)116, (unsigned short)119, (unsigned short)119, (unsigned short)126, (unsigned short)126, (unsigned short)128, (unsigned short)128, (unsigned short)156, (unsigned short)156, (unsigned short)10023, (unsigned short)10025, (unsigned short)10368, (unsigned short)10453, (unsigned short)20588, (unsigned short)20588, (unsigned short)20592, (unsigned short)20592, (unsigned short)21150, (unsigned short)21150>'
..., rSh=..., bAllCellAttrs=true) at /home/alvarezp/src/libreoffice/core/sw/source/uibase/uiview/formatclipboard.cxx:143

#10 0x00007fff9a3a718d in SwFormatClipboard::Copy(SwWrtShell&, SfxItemPool&, bool) (this=0x555559c52df0, rWrtShell=..., rPool=..., bPersistentCopy=false) at /home/alvarezp/src/libreoffice/core/sw/source/uibase/uiview/formatclipboard.cxx:403

#11 0x00007fff9a3d83fb in SwView::ExecFormatPaintbrush(SfxRequest const&) (this=0x555559c63a50, rReq=...) at /home/alvarezp/src/libreoffice/core/sw/source/uibase/uiview/view1.cxx:176

#12 0x00007fff9a3d3c51 in SfxStubSwViewExecFormatPaintbrush(SfxShell*, SfxRequest&) (pShell=0x555559c63a50, rReq=...) at /home/alvarezp/src/libreoffice/core/workdir/SdiTarget/sw/sdi/swslots.hxx:15051

#13 0x00007ffff3d12568 in SfxDispatcher::Call_Impl(SfxShell&, SfxSlot const&, SfxRequest&, bool) (this=0x5555566f62c0, rShell=..., rSlot=..., rReq=..., bRecord=true) at /home/alvarezp/src/libreoffice/core/sfx2/source/control/dispatch.cxx:254


The patch diff has some reindentation. Ignoring whitespace (git -w show), the patch is:

commit 3e4aa127416a5947882e6644409468aa1ca039ae
Author:     Oliver Specht <oliver.specht@cib.de>
AuthorDate: Wed May 29 12:19:24 2024 +0200
Commit:     Thorsten Behrens <thorsten.behrens@allotropia.de>
CommitDate: Mon Jul 15 20:10:24 2024 +0200

    tdf#122756 clone formatting includes table number format
    
    In clone formatting the number format of the current cell(s)
    is copied and applied if the target is a table
    
    Change-Id: I0b7dc1d5015aeb2262c8d37f76442519c5b6d655
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168184
    Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/uiview/formatclipboard.cxx b/sw/source/uibase/uiview/formatclipboard.cxx
index 1878b3efc209..1d5d1f80c39c 100644
--- a/sw/source/uibase/uiview/formatclipboard.cxx
+++ b/sw/source/uibase/uiview/formatclipboard.cxx
@@ -23,6 +23,7 @@
 #include <formatclipboard.hxx>
 
 #include <cmdid.h>
+#include <cellatr.hxx>
 #include <charfmt.hxx>
 #include <frmfmt.hxx>
 #include <docstyle.hxx>
@@ -91,7 +92,9 @@ std::unique_ptr<SfxItemSet> lcl_CreateEmptyItemSet( SelectionType nSelectionType
     return pItemSet;
 }
 
-void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
+void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh, bool bAllCellAttrs )
+{
+    if (bAllCellAttrs)
     {
         std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
         rSh.GetBoxBackground(aBrush);
@@ -137,6 +140,8 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
         if(pSplit)
             rSet.Put(std::move(pSplit));
     }
+    rSh.GetTableBoxFormulaAttrs(rSet);
+}
 
 void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
 {
@@ -216,6 +221,10 @@ void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
 
     if( const SwFormatRowSplit* pSplitItem = rSet.GetItemIfSet( RES_ROW_SPLIT, false ) )
         rSh.SetRowSplit(*pSplitItem);
+
+    if (rSet.GetItemIfSet( RES_BOXATR_FORMAT, false ))
+        rSh.SetTableBoxFormulaAttrs(rSet);
+
 }
 }//end anonymous namespace
 
@@ -364,8 +373,11 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP
         }
     }
 
-    if( nSelectionType & SelectionType::TableCell )//only copy table attributes if really cells are selected (not only text in tables)
+    if(nSelectionType & (SelectionType::Table | SelectionType::TableCell))
+    {
+        if (nSelectionType & SelectionType::TableCell)
         {
+            //only copy all table attributes if really cells are selected (not only text in tables)
             m_pTableItemSet = std::make_unique<SfxItemSetFixed<
                 RES_PAGEDESC, RES_BREAK,
                 RES_BACKGROUND, RES_SHADOW, // RES_BOX is inbetween
@@ -373,13 +385,22 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP
                 RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
                 RES_FRAMEDIR, RES_FRAMEDIR,
                 RES_ROW_SPLIT, RES_ROW_SPLIT,
+                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
                 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW,
                     // SID_ATTR_BORDER_OUTER is inbetween
                 SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
                 FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
                 FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
                 FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE>>(rPool);
-        lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
+        }
+        else
+        {
+            //selection in table should copy number format
+            m_pTableItemSet = std::make_unique<SfxItemSetFixed<
+                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>>(rPool);
+        }
+
+        lcl_getTableAttributes( *m_pTableItemSet, rWrtShell, nSelectionType & SelectionType::TableCell ? true : false);
     }
 
     m_nSelectionType = nSelectionType;