sc/inc/globstr.hrc            |    1 +
 sc/source/ui/inc/datafdlg.hxx |    2 +-
 sc/source/ui/view/cellsh2.cxx |   13 +++++++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

New commits:
commit 07203b8ed8cc7a392c196b695c9a5c60955b732b
Author:     Hossein <[email protected]>
AuthorDate: Wed Jan 24 01:17:28 2024 +0100
Commit:     Hossein <[email protected]>
CommitDate: Mon Jan 29 13:19:40 2024 +0100

    tdf#158426 Limit field columns for data form to 32
    
    Previously, maximum number of field columns for data form was 256, which
    was too much. But, even with that value, nothing was happening when
    exceeding that threshold. With this patch, the limit is decreased to 32,
    and if the user goes beyond this limit by selecting more columns, an
    error message is displayed. This change is done to prevent LibreOffice
    hang when excessive number of filed columns are selected and using data
    form is requested.
    
    Change-Id: Ib6189b5b3beffb26a3fd8ba8cd06e4ae213f77da
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162488
    Tested-by: Jenkins
    Reviewed-by: Hossein <[email protected]>

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 876fd231a316..b5badb52dff3 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -219,6 +219,7 @@
 #define STR_MATRIXFRAGMENTERR                   NC_("STR_MATRIXFRAGMENTERR", 
"You cannot change only part of an array.")
 #define STR_PAGEHEADER                          NC_("STR_PAGEHEADER", "Header")
 #define STR_PAGEFOOTER                          NC_("STR_PAGEFOOTER", "Footer")
+#define STR_TOO_MANY_COLUMNS_DATA_FORM          
NC_("STR_TOO_MANY_COLUMNS_DATA_FORM", "Too many columns in the data form.")
 
 /* BEGIN error constants and error strings. */
 #define STR_ERROR_STR                           NC_("STR_ERROR_STR", "Err:")
diff --git a/sc/source/ui/inc/datafdlg.hxx b/sc/source/ui/inc/datafdlg.hxx
index 4a05cbf1a1fc..cb61d0cc3cc5 100644
--- a/sc/source/ui/inc/datafdlg.hxx
+++ b/sc/source/ui/inc/datafdlg.hxx
@@ -16,7 +16,7 @@
 class ScTabViewShell;
 class ScDocument;
 
-#define MAX_DATAFORM_COLS   256
+#define MAX_DATAFORM_COLS   32
 #define MAX_DATAFORM_ROWS   32000
 
 class ScDataFormDlg : public weld::GenericDialogController
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 8911cb33fbc1..5fbde9ca526f 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -53,6 +53,7 @@
 #include <validat.hxx>
 #include <validate.hxx>
 #include <datamapper.hxx>
+#include <datafdlg.hxx>
 
 #include <scui_def.hxx>
 #include <scabstdlg.hxx>
@@ -353,6 +354,18 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
 
         case SID_DATA_FORM:
             {
+                ScViewData& rData = GetViewData();
+                ScRange aRange;
+                rData.GetSimpleArea( aRange );
+                ScAddress aStart = aRange.aStart;
+                ScAddress aEnd = aRange.aEnd;
+
+                if((aEnd.Col() - aStart.Col()) >= MAX_DATAFORM_COLS)
+                {
+                    
rData.GetDocShell()->ErrorMessage(STR_TOO_MANY_COLUMNS_DATA_FORM);
+                    break;
+                }
+
                 ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
 
                 VclPtr<AbstractScDataFormDlg> pDlg(pFact->CreateScDataFormDlg(

Reply via email to