From 5992e15796131f9814d9fb22cf807a2ee530d264 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Thu, 24 Nov 2011 01:19:10 -0500 Subject: i#97680, fdo#43152: Load this file without crashing. The document contains invalid sheet names. We check it on load, sees it invalid, decide not to append sheet. The next time the importer tries to put cell data into it thinking the sheet has already been created, the sheet instance is not there, and it crashes. The solution I used is to go ahead and append new sheet with a default name in case the supplied sheet name is invalid. --- sc/source/core/data/document.cxx | 17 ++++++++++------- sc/source/filter/xml/xmlsubti.cxx | 14 -------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 5a50aef4ac52..52dc4cee7ab7 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -334,14 +334,15 @@ void ScDocument::CreateValidTabName(rtl::OUString& rName) const for ( SCTAB i = static_cast(maTabs.size())+1; !bOk ; i++ ) { - rName = aStrTable; - rName += rtl::OUString::valueOf(static_cast(i)); + rtl::OUStringBuffer aBuf; + aBuf.append(aStrTable); + aBuf.append(static_cast(i)); + rName = aBuf.makeStringAndClear(); if (bPrefix) bOk = ValidNewTabName( rName ); else bOk = !GetTable( rName, nDummy ); } - } else { @@ -398,11 +399,13 @@ void ScDocument::CreateValidTabNames(std::vector& aNames, SCTAB n void ScDocument::AppendTabOnLoad(const rtl::OUString& rName) { SCTAB nTabCount = static_cast(maTabs.size()); + if (!ValidTab(nTabCount)) + // max table count reached. No more tables. + return; - if (ValidTab(nTabCount) && ValidNewTabName(rName)) - { - maTabs.push_back( new ScTable(this, nTabCount, rName) ); - } + rtl::OUString aName = rName; + CreateValidTabName(aName); + maTabs.push_back( new ScTable(this, nTabCount, aName) ); } diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 315bf2ba631c..3ea979fe59c6 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -648,20 +648,6 @@ void ScMyTables::DeleteTable() pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells); rImport.GetDocument()->SetTabProtection(nCurrentSheet, pProtect.get()); } - - //#95582#; find out whether it was possible to set the sheet name - // test it here, because if it is a linked table the name is changed by importing - // the linking informations - uno::Reference < container::XNamed > xNamed(xCurrentSheet, uno::UNO_QUERY ); - if ( xNamed.is() ) - { - rtl::OUString sCurrentName(xNamed->getName()); - if (sCurrentName != sCurrentSheetName && rImport.GetDocument()) - { - rImport.GetDocument()->RenameTab( nCurrentSheet, - sCurrentSheetName, false, true); - } - } } table::CellAddress ScMyTables::GetRealCellPos() -- cgit