From a1fa358d4769e9ddae1dad54c16885fcc210dac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sun, 27 Sep 2026 15:32:53 +0000 Subject: [PATCH] don't create the document BasicManager on save to check module sizes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creating it loads every Basic library of the document. Only an existing BasicManager can have loaded the password protected modules that the size check looks at. Signed-off-by: Caolán McNamara Change-Id: I1a66c4738d9a91cda785f0603c6f4fd6e6549802 Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/13628 Reviewed-by: Noel Grandin (cherry picked from commit 35fb01a50f47698e9b059b75c2a3b88699579fac) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211524 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- basic/source/basmgr/basicmanagerrepository.cxx | 15 +++++++++++++++ include/basic/basicmanagerrepository.hxx | 7 +++++++ sfx2/source/doc/objstor.cxx | 15 +++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/basic/source/basmgr/basicmanagerrepository.cxx b/basic/source/basmgr/basicmanagerrepository.cxx index 16f5b63626ce..f5668732b23d 100644 --- a/basic/source/basmgr/basicmanagerrepository.cxx +++ b/basic/source/basmgr/basicmanagerrepository.cxx @@ -79,6 +79,7 @@ namespace basic static ImplRepository& Instance(); BasicManager* getDocumentBasicManager( const Reference< XModel >& _rxDocumentModel ); + BasicManager* getExistingDocumentBasicManager( const Reference< XModel >& _rxDocumentModel ) const; BasicManager* getOrCreateApplicationBasicManager(); static BasicManager* getApplicationBasicManager(); static void setApplicationBasicManager( std::unique_ptr _pBasicManager ); @@ -236,6 +237,15 @@ namespace basic return nullptr; } + BasicManager* ImplRepository::getExistingDocumentBasicManager( const Reference< XModel >& _rxDocumentModel ) const + { + SolarMutexGuard g; + + Reference< XInterface > xNormalized( _rxDocumentModel, UNO_QUERY ); + auto const loc = m_aStore.find( xNormalized ); + return loc != m_aStore.end() ? loc->second.get() : nullptr; + } + BasicManager* ImplRepository::getOrCreateApplicationBasicManager() { SolarMutexGuard g; @@ -600,6 +610,11 @@ namespace basic return ImplRepository::Instance().getDocumentBasicManager( _rxDocumentModel ); } + BasicManager* BasicManagerRepository::getExistingDocumentBasicManager( const Reference< XModel >& _rxDocumentModel ) + { + return ImplRepository::Instance().getExistingDocumentBasicManager( _rxDocumentModel ); + } + BasicManager* BasicManagerRepository::getApplicationBasicManager() { return ImplRepository::Instance().getOrCreateApplicationBasicManager(); diff --git a/include/basic/basicmanagerrepository.hxx b/include/basic/basicmanagerrepository.hxx index 13620e509ba3..2d78a291cba3 100644 --- a/include/basic/basicmanagerrepository.hxx +++ b/include/basic/basicmanagerrepository.hxx @@ -94,6 +94,13 @@ namespace basic const css::uno::Reference< css::frame::XModel >& _rxDocumentModel ); + /** returns the BasicManager of the given document model, or if it has + not been created yet + */ + static BasicManager* getExistingDocumentBasicManager( + const css::uno::Reference< css::frame::XModel >& _rxDocumentModel + ); + /** returns the application-wide BasicManager @attention diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 1a95305b05c7..136b1678e5cf 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -93,6 +93,8 @@ #include #include #include +#include +#include #include #include #include @@ -4063,15 +4065,20 @@ bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< ta #if !HAVE_FEATURE_SCRIPTING (void) xHandler; #else - if ( !HasBasic() ) + if ( pImpl->m_bNoBasicCapabilities ) + return true; + + // Only a loaded password-protected library has modules to check, and one is loaded only + // through an existing BasicManager. + BasicManager* pBasicManager + = basic::BasicManagerRepository::getExistingDocumentBasicManager( GetModel() ); + if ( !pBasicManager ) return true; - if ( !pImpl->aBasicManager.isValid() ) - GetBasicManager(); std::vector< OUString > sModules; if ( xHandler.is() ) { - if( pImpl->aBasicManager.ImgVersion12PsswdBinaryLimitExceeded( sModules ) ) + if( pBasicManager->ImgVersion12PsswdBinaryLimitExceeded( sModules ) ) { rtl::Reference pReq = new ModuleSizeExceeded( sModules ); xHandler->handle( pReq );