sc/inc/dbdocutl.hxx | 2 +- sc/source/core/data/dbdocutl.cxx | 3 ++- sc/source/ui/docshell/docsh8.cxx | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-)
New commits: commit 7b57ae6dc98092ad0f584bbf22ef05a5cdbdc3b7 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Fri May 16 12:45:10 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri May 16 16:26:57 2025 +0200 ofz#415190397 avoid OOM with huge amounts of error cells Change-Id: I7587063de5914030f7231e91643202f0f4782847 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185408 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins diff --git a/sc/inc/dbdocutl.hxx b/sc/inc/dbdocutl.hxx index 5fd1186d814e..f2ba84eacefc 100644 --- a/sc/inc/dbdocutl.hxx +++ b/sc/inc/dbdocutl.hxx @@ -40,7 +40,7 @@ public: StrData(); }; - static void PutData( ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, + static bool PutData( ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const css::uno::Reference< css::sdbc::XRow>& xRow, sal_Int32 nRowPos, tools::Long nType, bool bCurrency, StrData* pStrData = nullptr ); diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx index df373d991d17..620c4af52413 100644 --- a/sc/source/core/data/dbdocutl.cxx +++ b/sc/source/core/data/dbdocutl.cxx @@ -35,7 +35,7 @@ ScDatabaseDocUtil::StrData::StrData() : { } -void ScDatabaseDocUtil::PutData(ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, +bool ScDatabaseDocUtil::PutData(ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const uno::Reference<sdbc::XRow>& xRow, sal_Int32 nRowPos, tools::Long nType, bool bCurrency, StrData* pStrData) { @@ -196,6 +196,7 @@ void ScDatabaseDocUtil::PutData(ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB else rDoc.SetEmptyCell(aPos); } + return bError; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx index 6df8ec07d8e8..d2f99c89442e 100644 --- a/sc/source/ui/docshell/docsh8.cxx +++ b/sc/source/ui/docshell/docsh8.cxx @@ -23,6 +23,7 @@ #include <tools/urlobj.hxx> #include <svl/converter.hxx> #include <svl/numformat.hxx> +#include <comphelper/configuration.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/types.hxx> @@ -383,6 +384,7 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding SCROW nRow = 1; // 0 is column titles bool bEnd = false; + size_t nErrors(0); while ( !bEnd && xRowSet->next() ) { if (nRow <= m_pDocument->MaxRow()) @@ -392,10 +394,14 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding for (sal_Int32 i=0; i<nColCount; i++) { ScDatabaseDocUtil::StrData aStrData; - ScDatabaseDocUtil::PutData( *m_pDocument, nCol, nRow, 0, + bool bWasError = + ScDatabaseDocUtil::PutData( *m_pDocument, nCol, nRow, 0, xRow, i+1, pTypeArr[i], false, &aStrData ); + if (bWasError) + ++nErrors; + if (aStrData.mnStrLength > aColWidthParam[nCol].mnMaxTextLen) { aColWidthParam[nCol].mnMaxTextLen = aStrData.mnStrLength; @@ -410,6 +416,12 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding ++nCol; } + if (nErrors > 65535 && comphelper::IsFuzzing()) + { + bEnd = true; + nErr = ERRCODE_IO_GENERAL; + SAL_WARN("sc", "Too many errors: abandoning."); + } if (!bSimpleRow) rRowHeightsRecalc.setTrue(nRow, nRow); ++nRow;