diff options
author | Oliver Bolte <obo@openoffice.org> | 2004-11-17 12:41:05 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2004-11-17 12:41:05 +0000 |
commit | 959c5af635a1710799ff24eab364e48944450f4c (patch) | |
tree | f38254bdbb78048046e42b45723c1fac8b3c5f25 | |
parent | cd2e49f1fae47737216f4255e6227d25b9097d37 (diff) |
INTEGRATION: CWS fwkbugfix03 (1.3.30); FILE MERGED
2004/10/14 12:44:41 as 1.3.30.4: seek to 0 before you request first 4 bytes of the stream
2004/10/12 07:51:34 as 1.3.30.3: dont use in/out parameters if out params are enough
2004/10/11 17:42:41 as 1.3.30.2: RESYNC: (1.3-1.4); FILE MERGED
2004/09/09 08:08:03 mav 1.3.30.1: #i33968# check signature of a stream on opening
-rw-r--r-- | package/source/xstor/xfactory.cxx | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/package/source/xstor/xfactory.cxx b/package/source/xstor/xfactory.cxx index 44a02e9baa80..f564bc8b6f7f 100644 --- a/package/source/xstor/xfactory.cxx +++ b/package/source/xstor/xfactory.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xfactory.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: kz $ $Date: 2004-10-04 21:08:20 $ + * last change: $Author: obo $ $Date: 2004-11-17 13:41:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,6 +83,28 @@ using namespace ::com::sun::star; //------------------------------------------------------------------------- +sal_Bool CheckPackageSignature_Impl( const uno::Reference< io::XInputStream >& xInputStream, + const uno::Reference< io::XSeekable >& xSeekable ) +{ + if ( !xInputStream.is() || !xSeekable.is() ) + throw uno::RuntimeException(); + + if ( xSeekable->getLength() ) + { + uno::Sequence< sal_Int8 > aData( 4 ); + xSeekable->seek( 0 ); + sal_Int32 nRead = xInputStream->readBytes( aData, 4 ); + xSeekable->seek( 0 ); + + // TODO/LATER: should the disk spanned files be supported? + // 0x50, 0x4b, 0x07, 0x08 + return ( nRead == 4 && aData[0] == 0x50 && aData[1] == 0x4b && aData[2] == 0x03 && aData[3] == 0x04 ); + } + else + return sal_True; // allow to create a storage based on empty stream +} + +//------------------------------------------------------------------------- uno::Sequence< ::rtl::OUString > SAL_CALL OStorageFactory::impl_staticGetSupportedServiceNames() { uno::Sequence< ::rtl::OUString > aRet(2); @@ -242,6 +264,16 @@ uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstanceWithAr if ( ( nStorageMode & embed::ElementModes::WRITE ) ) throw uno::Exception(); // TODO: access denied + uno::Reference< io::XSeekable > xSeekable( xInputStream, uno::UNO_QUERY ); + if ( !xSeekable.is() ) + { + // TODO: wrap stream to let it be seekable + OSL_ENSURE( sal_False, "Nonseekable streams are not supported for now!\n" ); + } + + if ( !CheckPackageSignature_Impl( xInputStream, xSeekable ) ) + throw io::IOException(); // TODO: this is not a package file + return uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( new OStorage( xInputStream, nStorageMode, aPropsToSet, m_xFactory ) ), uno::UNO_QUERY ); @@ -259,6 +291,9 @@ uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstanceWithAr OSL_ENSURE( sal_False, "Nonseekable streams are not supported for now!\n" ); } + if ( !CheckPackageSignature_Impl( xStream->getInputStream(), xSeekable ) ) + throw io::IOException(); // TODO: this is not a package file + return uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( new OStorage( xStream, nStorageMode, aPropsToSet, m_xFactory ) ), uno::UNO_QUERY ); |