sc/source/core/tool/compiler.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
New commits: commit 8d5da57c259a3a3d09a0118846c75a269bf38cdf Author: Caolán McNamara <[email protected]> AuthorDate: Sun Oct 5 17:52:56 2025 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Mon Oct 20 14:35:22 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 (cherry picked from commit 7a6ebc8be8f5df795d1c9e0cca1a740ee2b62b27) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191986 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 86c5cc4e3117..7dc4815960c5 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -6642,6 +6642,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))) @@ -6886,7 +6896,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) {
