sc/source/core/tool/compiler.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
New commits: commit 7a6ebc8be8f5df795d1c9e0cca1a740ee2b62b27 Author: Caolán McNamara <[email protected]> AuthorDate: Sun Oct 5 17:52:56 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Mon Oct 6 13:28:20 2025 +0200 Threaded import crash in ScDocument::ShrinkToDataArea since possibly(?) https://gerrit.libreoffice.org/c/core/+/180773 one thread, importing sheet 0, uses ScDocument::ShrinkToDataArea for a range on sheet 1 while sheet 1 is importing on a different thread. Change-Id: Ia982e4c0af4859aacbca19420941f19ee85479eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191920 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index e3b9fadf79f5..4f86f07913ec 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -6641,6 +6641,16 @@ void ScCompiler::CorrectSumRange(const ScComplexRefData& rBaseRange, pNewSumRangeTok->IncRef(); } +// If we are loading, we might be loading each sheet in a separate thread at the same time +// It is unsafe to use ShrinkToDataArea on a range that refers to a different sheet whose +// columns and rows are still being added to. Even if it is the same sheet, it probably +// doesn't make sense to ShrinkToDataArea during document load. +static bool IsSafeToShrinkToDataArea(const ScDocument& rDoc) +{ + const bool bIsLoading = !rDoc.GetDocumentShell() || rDoc.GetDocumentShell()->IsLoading(); + return !bIsLoading; +} + void ScCompiler::AnnotateTrimOnDoubleRefs() { if (!pCode || !(*(pCode - 1))) @@ -6885,7 +6895,8 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() SCROW nTempStartRow = rRange.aStart.Row(); SCCOL nTempEndCol = rRange.aEnd.Col(); SCROW nTempEndRow = rRange.aEnd.Row(); - rDoc.ShrinkToDataArea(rRange.aStart.Tab(), nTempStartCol, nTempStartRow, nTempEndCol, nTempEndRow); + if (IsSafeToShrinkToDataArea(rDoc)) + rDoc.ShrinkToDataArea(rRange.aStart.Tab(), nTempStartCol, nTempStartRow, nTempEndCol, nTempEndRow); // check if range is still valid if (nTempStartRow <= nTempEndRow && nTempStartCol <= nTempEndCol) {
