diff options
-rw-r--r-- | package/inc/Inflater.hxx | 4 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 59 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.hxx | 2 | ||||
-rw-r--r-- | package/source/zipapi/Inflater.cxx | 27 | ||||
-rw-r--r-- | package/source/zipapi/XUnbufferedStream.cxx | 6 |
5 files changed, 27 insertions, 71 deletions
diff --git a/package/inc/Inflater.hxx b/package/inc/Inflater.hxx index 7520ba672058..7805a9cc84bb 100644 --- a/package/inc/Inflater.hxx +++ b/package/inc/Inflater.hxx @@ -40,7 +40,7 @@ class Inflater { protected: sal_Bool bFinish, bFinished, bSetParams, bNeedDict; - sal_Int32 nOffset, nLength; + sal_Int32 nOffset, nLength, nLastInflateError; z_stream* pStream; com::sun::star::uno::Sequence < sal_Int8 > sInBuffer; sal_Int32 doInflateBytes (com::sun::star::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength); @@ -53,6 +53,8 @@ public: sal_Bool SAL_CALL finished( ); sal_Int32 SAL_CALL doInflateSegment( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength ); void SAL_CALL end( ); + + sal_Int32 getLastInflateError() { return nLastInflateError; } }; #endif diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 8b02a6114227..2946c14f98ff 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -743,65 +743,6 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream() return xInputStream; } -//----------------------------------------------- -void OWriteStream_Impl::CopyTempFileToOutput( uno::Reference< io::XOutputStream > xOutStream ) -{ - OSL_ENSURE( xOutStream.is(), "The stream must be specified!\n" ); - OSL_ENSURE( m_aTempURL.getLength() || m_xCacheStream.is(), "The temporary must exist!\n" ); - - uno::Reference< io::XInputStream > xTempInStream; - - if ( m_xCacheStream.is() ) - { - if ( !m_xCacheSeek.is() ) - throw uno::RuntimeException(); - sal_Int64 nPos = m_xCacheSeek->getPosition(); - - try - { - m_xCacheSeek->seek( 0 ); - uno::Reference< io::XInputStream > xTempInp = m_xCacheStream->getInputStream(); - if ( xTempInp.is() ) - ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream ); - } - catch( uno::Exception& aException ) - { - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - m_xCacheSeek->seek( nPos ); - throw io::IOException(); //TODO: - } - - m_xCacheSeek->seek( nPos ); - } - else if ( m_aTempURL.getLength() ) - { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - try - { - xTempInStream = xTempAccess->openFileRead( m_aTempURL ); - } - catch( uno::Exception& aException ) - { - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - - if ( !xTempInStream.is() ) - throw io::IOException(); //TODO: - - ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream ); - } -} - // ================================================================================================= //----------------------------------------------- diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx index 107ffd8f0ba8..9e4c00d5a45d 100644 --- a/package/source/xstor/owriteablestream.hxx +++ b/package/source/xstor/owriteablestream.hxx @@ -161,8 +161,6 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetTempFileAsStream(); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetTempFileAsInputStream(); - void CopyTempFileToOutput( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream ); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream_Impl( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ); diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx index 178767b06cdc..62228bf22c8e 100644 --- a/package/source/zipapi/Inflater.cxx +++ b/package/source/zipapi/Inflater.cxx @@ -45,12 +45,12 @@ using namespace com::sun::star::uno; /** Provides general purpose decompression using the ZLIB library */ Inflater::Inflater(sal_Bool bNoWrap) -: bFinish(sal_False), - bFinished(sal_False), +: bFinished(sal_False), bSetParams(sal_False), bNeedDict(sal_False), nOffset(0), nLength(0), + nLastInflateError(0), pStream(NULL) { pStream = new z_stream; @@ -120,16 +120,23 @@ void SAL_CALL Inflater::end( ) sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength) { - sal_Int32 nResult; + if ( !pStream ) + { + nLastInflateError = Z_STREAM_ERROR; + return 0; + } + + nLastInflateError = 0; + pStream->next_in = ( unsigned char* ) ( sInBuffer.getConstArray() + nOffset ); pStream->avail_in = nLength; pStream->next_out = reinterpret_cast < unsigned char* > ( rBuffer.getArray() + nNewOffset ); pStream->avail_out = nNewLength; #ifdef SYSTEM_ZLIB - nResult = ::inflate(pStream, bFinish ? Z_SYNC_FLUSH : Z_PARTIAL_FLUSH); + sal_Int32 nResult = ::inflate(pStream, Z_PARTIAL_FLUSH); #else - nResult = ::z_inflate(pStream, bFinish ? Z_SYNC_FLUSH : Z_PARTIAL_FLUSH); + sal_Int32 nResult = ::z_inflate(pStream, Z_PARTIAL_FLUSH); #endif switch (nResult) @@ -140,15 +147,19 @@ sal_Int32 Inflater::doInflateBytes (Sequence < sal_Int8 > &rBuffer, sal_Int32 n nOffset += nLength - pStream->avail_in; nLength = pStream->avail_in; return nNewLength - pStream->avail_out; + case Z_NEED_DICT: bNeedDict = sal_True; nOffset += nLength - pStream->avail_in; nLength = pStream->avail_in; - case Z_BUF_ERROR: - return 0; - case Z_DATA_ERROR: return 0; + + default: + // it is no error, if there is no input or no output + if ( nLength && nNewLength ) + nLastInflateError = nResult; } + return 0; } diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx index cb99c085bc28..1eba064a2165 100644 --- a/package/source/zipapi/XUnbufferedStream.cxx +++ b/package/source/zipapi/XUnbufferedStream.cxx @@ -230,7 +230,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa OUString( RTL_CONSTASCII_USTRINGPARAM( "Should not be possible to read more then requested!" ) ), Reference< XInterface >() ); - if ( maInflater.finished() ) + if ( maInflater.finished() || maInflater.getLastInflateError() ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), Reference< XInterface >() ); @@ -244,6 +244,10 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa mxZipSeek->seek ( mnZipCurrent ); sal_Int32 nToRead = std::min ( nDiff, std::max ( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ) ); sal_Int32 nZipRead = mxZipStream->readBytes ( maCompBuffer, nToRead ); + if ( nZipRead < nToRead ) + throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ), + Reference< XInterface >() ); + mnZipCurrent += nZipRead; // maCompBuffer now has the data, check if we need to decrypt // before passing to the Inflater |