diff options
author | Oliver Bolte <obo@openoffice.org> | 2009-02-12 10:27:21 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2009-02-12 10:27:21 +0000 |
commit | dcf97273b5f38bb86afda71051d6f789ad890ad8 (patch) | |
tree | 76a9afb23ebf302097092ab3d789a62aa01f2a5a | |
parent | 19f543c6007722f2e9984d24b7876291480f6b05 (diff) |
CWS-TOOLING: integrate CWS mav44
2009-01-18 22:39:43 +0100 mav r266467 : #i97073# the soffice file should be a shell script, adjust the plugin
2009-01-18 22:35:15 +0100 mav r266466 : #i97073# the soffice file should be a shell script, integrate fix from hro41 cws
2009-01-16 15:32:10 +0100 mav r266426 : #i96456# fix link resolving
2009-01-16 12:21:39 +0100 mav r266413 : #i97073# the soffice file is no more a shell script
2009-01-16 09:58:05 +0100 mav r266402 : #i95409# add complex test using unicode names
2009-01-15 20:27:03 +0100 mav r266392 : #i95408# fix include list
2009-01-15 20:09:28 +0100 mav r266390 : #i95408# deliver new header
2009-01-15 16:16:33 +0100 mav r266382 : #i95408# rebase to m38
2009-01-15 16:11:16 +0100 mav r266380 : #i95408# rebase to m38
2009-01-15 15:38:16 +0100 mav r266376 : CWS-TOOLING: rebase CWS mav44 to trunk@265758 (milestone: DEV300:m38)
2009-01-14 13:23:55 +0100 mav r266294 : #i97073# let the presentation slideshow be started in window mode in plugin
2009-01-13 17:27:52 +0100 mav r266241 : #i95409#,#i95408# support UTF8 encoding for entry names, check the validity of the entries
2009-01-13 16:35:39 +0100 mav r266236 : #i95408# function to check whether a zip entry name is acceptable
2009-01-13 12:00:18 +0100 mav r266205 : #i94003# a readonly document can not be modified
2009-01-09 13:24:49 +0100 mav r266078 : #i95951# let the title be changed
2009-01-09 11:34:49 +0100 mav r266068 : #i80862# close the link only if was closed by the container, othewise leave it open
2009-01-08 11:30:13 +0100 mav r265989 : #i97071# disable Toolbars during window-based slide show in ActiveX control
2009-01-08 08:23:23 +0100 mav r265983 : #i97071# setVisible does not trigger layout in case there is not MenuBar
2009-01-06 12:39:39 +0100 mav r265908 : #i96185# let the MediaDescriptor get the target URL
2009-01-05 08:46:45 +0100 mav r265856 : #i93473# integrate the patch
2009-01-02 17:45:17 +0100 mav r265845 : #i94468#,#i96456# try to follow links
2009-01-02 16:53:41 +0100 mav r265841 : #i94468#,#i96456# use the same parsing mechanics in sharing control file and document lock file
2009-01-02 16:51:24 +0100 mav r265839 : #i94468#,#i96456# use the same parsing mechanics in sharing control file and document lock file
-rw-r--r-- | embedserv/source/embed/docholder.cxx | 8 | ||||
-rwxr-xr-x | embedserv/source/embed/ed_ipersiststr.cxx | 13 | ||||
-rw-r--r-- | embedserv/source/inc/docholder.hxx | 3 | ||||
-rw-r--r-- | extensions/source/nsplugin/source/so_instance.cxx | 14 | ||||
-rw-r--r-- | extensions/source/nsplugin/source/so_main.cxx | 1 | ||||
-rw-r--r-- | package/inc/ByteChucker.hxx | 7 | ||||
-rw-r--r-- | package/qa/storages/StorageUnitTest.java | 8 | ||||
-rw-r--r-- | package/qa/storages/Test16.java | 159 | ||||
-rw-r--r-- | package/qa/storages/makefile.mk | 1 | ||||
-rw-r--r-- | package/source/xstor/xstorage.cxx | 97 | ||||
-rw-r--r-- | package/source/zipapi/ByteChucker.cxx | 18 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 13 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 58 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.cxx | 22 |
14 files changed, 313 insertions, 109 deletions
diff --git a/embedserv/source/embed/docholder.cxx b/embedserv/source/embed/docholder.cxx index 7664a2cad..e5cd64b9a 100644 --- a/embedserv/source/embed/docholder.cxx +++ b/embedserv/source/embed/docholder.cxx @@ -676,7 +676,7 @@ void DocumentHolder::FreeOffice() } } -void DocumentHolder::DisconnectFrameDocument() +void DocumentHolder::DisconnectFrameDocument( sal_Bool bComplete ) { try { @@ -704,6 +704,12 @@ void DocumentHolder::DisconnectFrameDocument() catch( uno::Exception& ) {} + if ( bComplete ) + { + m_xFrame = uno::Reference< frame::XFrame>(); + m_pIDispatch = NULL; + m_xDocument = uno::Reference< frame::XModel >(); + } } void DocumentHolder::CloseDocument() diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx index 46b60f299..240d25047 100755 --- a/embedserv/source/embed/ed_ipersiststr.cxx +++ b/embedserv/source/embed/ed_ipersiststr.cxx @@ -193,8 +193,17 @@ EmbedDocument_Impl::EmbedDocument_Impl( const uno::Reference< lang::XMultiServic EmbedDocument_Impl::~EmbedDocument_Impl() { m_pDocHolder->FreeOffice(); - m_pDocHolder->CloseDocument(); - m_pDocHolder->CloseFrame(); + + if ( m_pDocHolder->HasFrame() && m_pDocHolder->IsLink() ) + { + // a link with frame should be only disconnected, not closed + m_pDocHolder->DisconnectFrameDocument( sal_True ); + } + else + { + m_pDocHolder->CloseDocument(); + m_pDocHolder->CloseFrame(); + } m_pDocHolder->release(); } diff --git a/embedserv/source/inc/docholder.hxx b/embedserv/source/inc/docholder.hxx index 4b0cd918f..bd42bc092 100644 --- a/embedserv/source/inc/docholder.hxx +++ b/embedserv/source/inc/docholder.hxx @@ -168,7 +168,7 @@ public: sal_Bool ExecuteSuspendCloseFrame(); - void DisconnectFrameDocument(); + void DisconnectFrameDocument( sal_Bool bComplete = sal_False ); void CloseDocument(); void CloseFrame(); void ClearInterceptor(); @@ -185,6 +185,7 @@ public: void show(); sal_Bool HasFrame() { return m_xFrame.is(); } + sal_Bool IsLink() { return m_bLink; } /** hides the document window, even in case of an external container * side managed window. diff --git a/extensions/source/nsplugin/source/so_instance.cxx b/extensions/source/nsplugin/source/so_instance.cxx index 005a4af98..5bc895351 100644 --- a/extensions/source/nsplugin/source/so_instance.cxx +++ b/extensions/source/nsplugin/source/so_instance.cxx @@ -39,6 +39,8 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/presentation/XPresentation.hpp> +#include <com/sun/star/presentation/XPresentationSupplier.hpp> #include <tools/debug.hxx> #include <tools/color.hxx> #include <vcl/window.hxx> @@ -344,6 +346,18 @@ sal_Bool SoPluginInstance::LoadDocument(NSP_HWND hParent) m_dParentStyl = ::NSP_ResetWinStyl (m_hParent); #endif m_bInit = sal_True; + + try + { + // in case of presentation try to set the mode of slide-show, and start it + uno::Reference< presentation::XPresentationSupplier > xPresSuppl( m_xComponent, uno::UNO_QUERY_THROW ); + uno::Reference< presentation::XPresentation > xPres( xPresSuppl->getPresentation(), uno::UNO_SET_THROW ); + uno::Reference< beans::XPropertySet > xProps( xPresSuppl->getPresentation(), uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), uno::makeAny( sal_False ) ); + xPres->start(); + } + catch( uno::Exception& ) + {} } catch( uno::Exception& e ) { diff --git a/extensions/source/nsplugin/source/so_main.cxx b/extensions/source/nsplugin/source/so_main.cxx index 347be10fd..58ddf2687 100644 --- a/extensions/source/nsplugin/source/so_main.cxx +++ b/extensions/source/nsplugin/source/so_main.cxx @@ -415,6 +415,7 @@ Reference< lang::XMultiServiceFactory > SAL_CALL start_office(NSP_PIPE_FD read_f break; default: debug_fprintf(NSP_LOG_APPEND, "unmapped error!\n"); + return Reference< lang::XMultiServiceFactory >(NULL); } #endif diff --git a/package/inc/ByteChucker.hxx b/package/inc/ByteChucker.hxx index d627501ae..d0906c06b 100644 --- a/package/inc/ByteChucker.hxx +++ b/package/inc/ByteChucker.hxx @@ -53,11 +53,10 @@ public: ByteChucker (com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xOstream); ~ByteChucker(); - // XOutputStream - void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nLength = -1, const sal_Int8 * const pData = NULL) + void WriteBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - sal_Int64 SAL_CALL getPosition( ) + + sal_Int64 GetPosition() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); ByteChucker& operator << (sal_Int8 nInt8); diff --git a/package/qa/storages/StorageUnitTest.java b/package/qa/storages/StorageUnitTest.java index 0df85ccbd..34645469b 100644 --- a/package/qa/storages/StorageUnitTest.java +++ b/package/qa/storages/StorageUnitTest.java @@ -82,6 +82,7 @@ public class StorageUnitTest extends ComplexTestCase "ExecuteTest13", "ExecuteTest14", "ExecuteTest15", + "ExecuteTest16", "ExecuteRegressionTest_114358", "ExecuteRegressionTest_i29169", "ExecuteRegressionTest_i30400", @@ -220,6 +221,13 @@ public class StorageUnitTest extends ComplexTestCase assure( "Test15 failed!", aTest.test() ); } + public void ExecuteTest16() + { + StorageTest aTest = new Test16( m_xMSF, m_xStorageFactory, log ); + assure( "Test16 failed!", aTest.test() ); + } + + public void ExecuteRegressionTest_114358() { StorageTest aTest = new RegressionTest_114358( m_xMSF, m_xStorageFactory, log ); diff --git a/package/qa/storages/Test16.java b/package/qa/storages/Test16.java new file mode 100644 index 000000000..1b573dc12 --- /dev/null +++ b/package/qa/storages/Test16.java @@ -0,0 +1,159 @@ +package complex.storages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.embed.*; + +import share.LogWriter; +import complex.storages.TestHelper; +import complex.storages.StorageTest; + +public class Test16 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test16( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test16: " ); + } + + public boolean test() + { + try + { + String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); + if ( sTempFileURL == null || sTempFileURL == "" ) + { + m_aTestHelper.Error( "No valid temporary file was created!" ); + return false; + } + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + Object oTempStorage = m_xStorageFactory.createInstance(); + XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage\u0442\u0435\u0441\u04421", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) ) + return false; + + // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + "MediaType3", + true, + ElementModes.WRITE ) ) + return false; + + // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + "MediaType4", + false, + ElementModes.WRITE ) ) + return false; + + // create temporary storage based on a previously created temporary file + Object pArgs[] = new Object[2]; + pArgs[0] = (Object) sTempFileURL; + pArgs[1] = new Integer( ElementModes.WRITE ); + + Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); + XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + if ( xTempFileStorage == null ) + { + m_aTestHelper.Error( "Can't create storage based on temporary file!" ); + return false; + } + + // copy xTempStorage to xTempFileStorage + // xTempFileStorage will be automatically commited + if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) ) + return false; + + // ================================================ + // now check all the written and copied information + // ================================================ + + // the temporary file must not be locked any more after storage disposing + pArgs[1] = new Integer( ElementModes.WRITE ); + Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); + XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.WRITE ) ) + return false; + + // open existing substorage + XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage\u0442\u0435\u0441\u04421", + ElementModes.READ ); + if ( xResultSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType4", false, ElementModes.READ ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04421", "MediaType1", true, pBytes1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream\u0442\u0435\u0441\u04422", "MediaType2", false, pBytes2 ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/storages/makefile.mk b/package/qa/storages/makefile.mk index d78f51a60..7caa832a5 100644 --- a/package/qa/storages/makefile.mk +++ b/package/qa/storages/makefile.mk @@ -62,6 +62,7 @@ JAVAFILES =\ Test13.java\ Test14.java\ Test15.java\ + Test16.java\ RegressionTest_114358.java\ RegressionTest_i29169.java\ RegressionTest_i30400.java\ diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 0ce788c87..263ed59f6 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -48,9 +48,7 @@ #include <com/sun/star/beans/NamedValue.hpp> -#ifndef _COMPHELPER_PROCESSFACTORY_HXX #include <comphelper/processfactory.hxx> -#endif #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> #include <rtl/logfile.hxx> @@ -2402,8 +2400,8 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -2575,8 +2573,8 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStorName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -2714,8 +2712,8 @@ uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -2899,8 +2897,8 @@ void SAL_CALL OStorage::copyStorageElementLastCommitTo( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStorName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -2977,8 +2975,8 @@ sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -3032,8 +3030,8 @@ sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementNam if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -3091,8 +3089,8 @@ void SAL_CALL OStorage::removeElement( const ::rtl::OUString& aElementName ) if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -3167,8 +3165,9 @@ void SAL_CALL OStorage::renameElement( const ::rtl::OUString& aElementName, cons if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() || !aNewName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) + || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) @@ -3253,7 +3252,11 @@ void SAL_CALL OStorage::copyElementTo( const ::rtl::OUString& aElementName, if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() || !aNewName.getLength() || !xDest.is() ) + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) + || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !xDest.is() ) // || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) throw lang::IllegalArgumentException(); @@ -3334,8 +3337,11 @@ void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName, if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() || !aNewName.getLength() - || !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) + || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) throw lang::IllegalArgumentException(); if ( m_pData->m_nStorageType == OFOPXML_STORAGE @@ -3431,8 +3437,8 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement( if ( m_pData->m_nStorageType == OFOPXML_STORAGE ) throw uno::RuntimeException(); // the interface is not supported and must not be accessible - if ( !sStreamName.getLength() ) - throw lang::IllegalArgumentException(); // TODO + if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); uno::Reference < io::XInputStream > xTempIn; try @@ -3523,8 +3529,8 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement( if ( m_pData->m_nStorageType != PACKAGE_STORAGE ) throw packages::NoEncryptionException(); - if ( !sStreamName.getLength() ) - throw lang::IllegalArgumentException(); // TODO + if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); uno::Reference < io::XInputStream > xTempIn; try @@ -3623,7 +3629,10 @@ void SAL_CALL OStorage::insertRawEncrStreamElement( const ::rtl::OUString& aStre if ( m_pData->m_nStorageType != PACKAGE_STORAGE ) throw packages::NoEncryptionException(); - if ( !aStreamName.getLength() || !xInStream.is() ) + if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !xInStream.is() ) throw lang::IllegalArgumentException(); // TODO if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) @@ -3913,8 +3922,8 @@ uno::Any SAL_CALL OStorage::getByName( const ::rtl::OUString& aName ) if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -4915,8 +4924,8 @@ void SAL_CALL OStorage::insertStreamElementDirect( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -4990,8 +4999,11 @@ void SAL_CALL OStorage::copyElementDirectlyTo( if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() || !aNewName.getLength() || !xDest.is() - || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) + || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) throw lang::IllegalArgumentException(); if ( m_pData->m_nStorageType == OFOPXML_STORAGE @@ -5194,8 +5206,8 @@ uno::Any SAL_CALL OStorage::getElementPropertyValue( const ::rtl::OUString& aEle if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aElementName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -5275,8 +5287,8 @@ void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamNam if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamName.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) @@ -5347,8 +5359,8 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamEle if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamPath.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) && ( nOpenMode & embed::ElementModes::WRITE ) ) @@ -5407,7 +5419,10 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted if ( m_pData->m_nStorageType != PACKAGE_STORAGE ) packages::NoEncryptionException(); // TODO: - if ( !aStreamPath.getLength() || !sPassword.getLength() ) + if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !sPassword.getLength() ) throw lang::IllegalArgumentException(); if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) @@ -5464,8 +5479,8 @@ void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUSt if ( !m_pImpl ) throw lang::DisposedException(); - if ( !aStreamPath.getLength() ) - throw lang::IllegalArgumentException(); + if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) throw io::IOException(); // Access denied diff --git a/package/source/zipapi/ByteChucker.cxx b/package/source/zipapi/ByteChucker.cxx index b14c8cfee..3b609445a 100644 --- a/package/source/zipapi/ByteChucker.cxx +++ b/package/source/zipapi/ByteChucker.cxx @@ -55,15 +55,13 @@ ByteChucker::~ByteChucker() { } -// XOutputStream chained... -void SAL_CALL ByteChucker::writeBytes( const Sequence< sal_Int8 >& aData, sal_Int32 /*nLength*/, const sal_Int8 * const /*pData*/ ) +void ByteChucker::WriteBytes( const Sequence< sal_Int8 >& aData ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) { xStream->writeBytes(aData); } -// XSeekable chained... -sal_Int64 SAL_CALL ByteChucker::getPosition( ) +sal_Int64 ByteChucker::GetPosition( ) throw(IOException, RuntimeException) { return xSeek->getPosition(); @@ -72,7 +70,7 @@ sal_Int64 SAL_CALL ByteChucker::getPosition( ) ByteChucker& ByteChucker::operator << (sal_Int8 nInt8) { p1Sequence[0] = nInt8 & 0xFF; - writeBytes( a1Sequence, 1, p1Sequence ); + WriteBytes( a1Sequence ); return *this; } @@ -80,7 +78,7 @@ ByteChucker& ByteChucker::operator << (sal_Int16 nInt16) { p2Sequence[0] = static_cast< sal_Int8 >((nInt16 >> 0 ) & 0xFF); p2Sequence[1] = static_cast< sal_Int8 >((nInt16 >> 8 ) & 0xFF); - writeBytes( a2Sequence, 2, p2Sequence ); + WriteBytes( a2Sequence ); return *this; } ByteChucker& ByteChucker::operator << (sal_Int32 nInt32) @@ -89,21 +87,21 @@ ByteChucker& ByteChucker::operator << (sal_Int32 nInt32) p4Sequence[1] = static_cast< sal_Int8 >((nInt32 >> 8 ) & 0xFF); p4Sequence[2] = static_cast< sal_Int8 >((nInt32 >> 16 ) & 0xFF); p4Sequence[3] = static_cast< sal_Int8 >((nInt32 >> 24 ) & 0xFF); - writeBytes( a4Sequence, 4, p4Sequence ); + WriteBytes( a4Sequence ); return *this; } ByteChucker& ByteChucker::operator << (sal_uInt8 nuInt8) { p1Sequence[0] = nuInt8 & 0xFF; - writeBytes( a1Sequence, 1, p1Sequence ); + WriteBytes( a1Sequence ); return *this; } ByteChucker& ByteChucker::operator << (sal_uInt16 nuInt16) { p2Sequence[0] = static_cast< sal_Int8 >((nuInt16 >> 0 ) & 0xFF); p2Sequence[1] = static_cast< sal_Int8 >((nuInt16 >> 8 ) & 0xFF); - writeBytes( a2Sequence, 2, p2Sequence ); + WriteBytes( a2Sequence ); return *this; } ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32) @@ -112,6 +110,6 @@ ByteChucker& ByteChucker::operator << (sal_uInt32 nuInt32) p4Sequence[1] = static_cast < sal_Int8 > ((nuInt32 >> 8 ) & 0xFF); p4Sequence[2] = static_cast < sal_Int8 > ((nuInt32 >> 16 ) & 0xFF); p4Sequence[3] = static_cast < sal_Int8 > ((nuInt32 >> 24 ) & 0xFF); - writeBytes( a4Sequence, 4, p4Sequence ); + WriteBytes( a4Sequence ); return *this; } diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index c2a6e41a5..9f426ea7f 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -54,6 +54,8 @@ #include <string.h> // for memcpy #include <vector> +#include <comphelper/storagehelper.hxx> + using namespace vos; using namespace rtl; using namespace com::sun::star; @@ -753,9 +755,13 @@ sal_Int32 ZipFile::readCEN() if ( aEntry.nExtraLen < 0 || aEntry.nExtraLen > ZIP_MAXEXTRA ) throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "extra header info exceeds ZIP_MAXEXTRA bytes") ), Reference < XInterface > () ); + // read always in UTF8, some tools seem not to set UTF8 bit aEntry.sName = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), aEntry.nNameLen, - RTL_TEXTENCODING_ASCII_US); + RTL_TEXTENCODING_UTF8 ); + + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sName, sal_True ) ) + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () ); aMemGrabber.skipBytes( aEntry.nNameLen + aEntry.nExtraLen + nCommentLen ); aEntries[aEntry.sName] = aEntry; @@ -833,10 +839,11 @@ sal_Int32 ZipFile::recover() if ( aEntry.nNameLen <= ZIP_MAXNAMELEN && aEntry.nExtraLen < ZIP_MAXEXTRA && ( nGenPos + nPos + nBlockLength ) <= nLength ) { + // read always in UTF8, some tools seem not to set UTF8 bit if( nPos + 30 + aEntry.nNameLen <= nBufSize ) aEntry.sName = OUString ( (sal_Char *) &pBuffer[nPos + 30], aEntry.nNameLen, - RTL_TEXTENCODING_ASCII_US); + RTL_TEXTENCODING_UTF8 ); else { Sequence < sal_Int8 > aFileName; @@ -844,7 +851,7 @@ sal_Int32 ZipFile::recover() aGrabber.readBytes( aFileName, aEntry.nNameLen ); aEntry.sName = OUString ( (sal_Char *) aFileName.getArray(), aFileName.getLength(), - RTL_TEXTENCODING_ASCII_US); + RTL_TEXTENCODING_UTF8 ); aEntry.nNameLen = static_cast< sal_Int16 >(aFileName.getLength()); } diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index bc23edce4..1614580fd 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -40,9 +40,8 @@ #include <vos/ref.hxx> #endif #include <com/sun/star/io/XOutputStream.hpp> -#if OSL_DEBUG_LEVEL > 0 -#include <ImplValidCharacters.hxx> -#endif + +#include <comphelper/storagehelper.hxx> using namespace rtl; using namespace com::sun::star::io; @@ -96,12 +95,10 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, if (rEntry.nMethod == -1) rEntry.nMethod = nMethod; rEntry.nVersion = 20; + rEntry.nFlag = 1 << 11; if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || rEntry.nCrc == -1) - rEntry.nFlag = 8; - else if (rEntry.nSize != -1 && rEntry.nCompressedSize != -1 && - rEntry.nCrc != -1) - rEntry.nFlag = 0; + rEntry.nFlag |= 8; if (bEncrypt) { @@ -121,7 +118,7 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, pCurrentEncryptData = xEncryptData.getBodyPtr(); } sal_Int32 nLOCLength = writeLOC(rEntry); - rEntry.nOffset = static_cast < sal_Int32 > (aChucker.getPosition()) - nLOCLength; + rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength; aZipList.push_back( &rEntry ); pCurrentEntry = &rEntry; } @@ -212,7 +209,7 @@ void SAL_CALL ZipOutputStream::write( const Sequence< sal_Int8 >& rBuffer, sal_I case STORED: { Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - aChucker.writeBytes( aTmpBuffer ); + aChucker.WriteBytes( aTmpBuffer ); } break; } @@ -222,7 +219,7 @@ void SAL_CALL ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int3 throw(IOException, RuntimeException) { Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength ); - aChucker.writeBytes( aTmpBuffer ); + aChucker.WriteBytes( aTmpBuffer ); } void SAL_CALL ZipOutputStream::rawCloseEntry( ) @@ -245,10 +242,10 @@ void SAL_CALL ZipOutputStream::finish( ) if (aZipList.size() < 1) OSL_ENSURE(false,"Zip file must have at least one entry!\n"); - sal_Int32 nOffset= static_cast < sal_Int32 > (aChucker.getPosition()); + sal_Int32 nOffset= static_cast < sal_Int32 > (aChucker.GetPosition()); for (sal_Int32 i =0, nEnd = aZipList.size(); i < nEnd; i++) writeCEN( *aZipList[i] ); - writeEND( nOffset, static_cast < sal_Int32 > (aChucker.getPosition()) - nOffset); + writeEND( nOffset, static_cast < sal_Int32 > (aChucker.GetPosition()) - nOffset); bFinished = sal_True; xStream->flush(); } @@ -282,12 +279,12 @@ void ZipOutputStream::doDeflate() nLength, reinterpret_cast < sal_uInt8 * > (aEncryptionBuffer.getArray()), nLength ); OSL_ASSERT( aCipherResult == rtl_Cipher_E_None ); - aChucker.writeBytes ( aEncryptionBuffer ); + aChucker.WriteBytes( aEncryptionBuffer ); aCRC.update ( aEncryptionBuffer ); aEncryptionBuffer.realloc ( nOldLength ); } else - aChucker.writeBytes ( aTmpBuffer ); + aChucker.WriteBytes ( aTmpBuffer ); } } void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) @@ -305,7 +302,11 @@ void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { - sal_Int16 nNameLength = static_cast < sal_Int16 > ( rEntry.sName.getLength() ); + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sName, sal_True ) ) + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + + ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sName, RTL_TEXTENCODING_UTF8 ); + sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); aChucker << CENSIG; aChucker << rEntry.nVersion; @@ -335,15 +336,8 @@ void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) aChucker << static_cast < sal_Int32> (0); aChucker << rEntry.nOffset; - const sal_Unicode *pChar = rEntry.sName.getStr(); - Sequence < sal_Int8 > aSequence (nNameLength); - sal_Int8 *pArray = aSequence.getArray(); - - OSL_ENSURE ( Impl_IsValidChar ( pChar, nNameLength, sal_True ), "Non US ASCII character in zipentry name!"); - for ( sal_Int16 i = 0; i < nNameLength; i++) - pArray[i] = static_cast < const sal_Int8 > (pChar[i]); - - aChucker.writeBytes( aSequence, nNameLength, pArray ); + Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); + aChucker.WriteBytes( aSequence ); } void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) throw(IOException, RuntimeException) @@ -357,9 +351,11 @@ void ZipOutputStream::writeEXT( const ZipEntry &rEntry ) sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { - sal_Int16 nNameLength = static_cast < sal_Int16 > (rEntry.sName.getLength()); - Sequence < sal_Int8 > aSequence(nNameLength); - sal_Int8 *pArray = aSequence.getArray(); + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sName, sal_True ) ) + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + + ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sName, RTL_TEXTENCODING_UTF8 ); + sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); aChucker << LOCSIG; aChucker << rEntry.nVersion; @@ -394,11 +390,9 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) aChucker << nNameLength; aChucker << static_cast < sal_Int16 > (0); - const sal_Unicode *pChar = rEntry.sName.getStr(); - OSL_ENSURE ( Impl_IsValidChar ( pChar, nNameLength, sal_True ), "Non US ASCII character in zipentry name!"); - for ( sal_Int16 i = 0; i < nNameLength; i++) - pArray[i] = static_cast < const sal_Int8 > (pChar[i]); - aChucker.writeBytes( aSequence, nNameLength, pArray ); + Sequence < sal_Int8 > aSequence( (sal_Int8*)sUTF8Name.getStr(), sUTF8Name.getLength() ); + aChucker.WriteBytes( aSequence ); + return LOCHDR + nNameLength; } sal_uInt32 ZipOutputStream::getCurrentDosTime( ) diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 06a5e1d29..c4252425b 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -36,21 +36,12 @@ #endif #include <vos/diagnose.hxx> -#if defined( OSL_DEBUG ) -#if OSL_DEBUG > 0 -#include <ImplValidCharacters.hxx> -#endif -#endif #include <ZipPackageFolder.hxx> #include <ZipPackageStream.hxx> #include <ContentInfo.hxx> -#if defined( OSL_DEBUG_LEVEL ) -#if OSL_DEBUG_LEVEL > 0 -#include <ImplValidCharacters.hxx> -#endif -#endif - +#include <comphelper/storagehelper.hxx> + using namespace rtl; using namespace com::sun::star; using namespace com::sun::star::uno; @@ -84,10 +75,11 @@ void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) if ( pParent && pParent->hasByName ( aEntry.sName ) ) pParent->removeByName ( aEntry.sName ); - const sal_Unicode *pChar = aName.getStr(); - if(pChar == 0 || pChar != 0) { - VOS_ENSURE ( Impl_IsValidChar (pChar, static_cast < sal_Int16 > ( aName.getLength() ), sal_False), "Invalid character in new zip package entry name!"); - } + // unfortunately no other exception than RuntimeException can be thrown here + // usually the package is used through storage implementation, the problem should be detected there + if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + aEntry.sName = aName; if ( pParent ) |