[Libreoffice-commits] core.git: 2 commits - filter/source sdext/source sfx2/source
Stephan Bergmann
sbergman at redhat.com
Thu Sep 10 07:39:53 PDT 2015
filter/source/svg/svgfilter.cxx | 56 +++++++++---------
sdext/source/pdfimport/filterdet.cxx | 107 ++++++++++++++++++-----------------
sfx2/source/doc/docfile.cxx | 1
3 files changed, 86 insertions(+), 78 deletions(-)
New commits:
commit 8ac129a59b237e561b0884a2643030c2ce1175dd
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Sep 10 16:39:24 2015 +0200
Handle IOException during filter detection
Change-Id: Ie2b8b65f0f2b7b34efbba478a7ccda7ef3719bd6
diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx
index b3a56df..0f20f8f 100644
--- a/filter/source/svg/svgfilter.cxx
+++ b/filter/source/svg/svgfilter.cxx
@@ -360,32 +360,36 @@ OUString SAL_CALL SVGFilter::detect(Sequence<PropertyValue>& rDescriptor) throw
if (!xInput.is())
return OUString();
- if (isStreamGZip(xInput))
- {
- boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInput, true ));
- if(!aStream.get())
- return OUString();
-
- SvStream* pMemoryStream = new SvMemoryStream;
- uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY);
- if (!xSeek.is())
- return OUString();
- xSeek->seek(0);
-
- ZCodec aCodec;
- aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
- aCodec.Decompress(*aStream.get(), *pMemoryStream);
- aCodec.EndCompression();
- pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN);
- uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
-
- if (xDecompressedInput.is() && isStreamSvg(xDecompressedInput))
- return OUString(constFilterName);
- }
- else
- {
- if (isStreamSvg(xInput))
- return OUString(constFilterName);
+ try {
+ if (isStreamGZip(xInput))
+ {
+ boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInput, true ));
+ if(!aStream.get())
+ return OUString();
+
+ SvStream* pMemoryStream = new SvMemoryStream;
+ uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY);
+ if (!xSeek.is())
+ return OUString();
+ xSeek->seek(0);
+
+ ZCodec aCodec;
+ aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
+ aCodec.Decompress(*aStream.get(), *pMemoryStream);
+ aCodec.EndCompression();
+ pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN);
+ uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
+
+ if (xDecompressedInput.is() && isStreamSvg(xDecompressedInput))
+ return OUString(constFilterName);
+ }
+ else
+ {
+ if (isStreamSvg(xInput))
+ return OUString(constFilterName);
+ }
+ } catch (css::io::IOException & e) {
+ SAL_WARN("filter", "caught IOException " + e.Message);
}
return OUString();
}
diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx
index e966529..af89ee7 100644
--- a/sdext/source/pdfimport/filterdet.cxx
+++ b/sdext/source/pdfimport/filterdet.cxx
@@ -229,73 +229,78 @@ OUString SAL_CALL PDFDetector::detect( uno::Sequence< beans::PropertyValue >& rF
}
if( xInput.is() )
{
- uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
- if( xSeek.is() )
- xSeek->seek( 0 );
- // read the first 1024 byte (see PDF reference implementation note 12)
- const sal_Int32 nHeaderSize = 1024;
- uno::Sequence< sal_Int8 > aBuf( nHeaderSize );
- sal_uInt64 nBytes = 0;
- nBytes = xInput->readBytes( aBuf, nHeaderSize );
- if( nBytes > 5 )
- {
- const sal_Int8* pBytes = aBuf.getConstArray();
- for( unsigned int i = 0; i < nBytes-5; i++ )
+ oslFileHandle aFile = NULL;
+ try {
+ uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
+ if( xSeek.is() )
+ xSeek->seek( 0 );
+ // read the first 1024 byte (see PDF reference implementation note 12)
+ const sal_Int32 nHeaderSize = 1024;
+ uno::Sequence< sal_Int8 > aBuf( nHeaderSize );
+ sal_uInt64 nBytes = 0;
+ nBytes = xInput->readBytes( aBuf, nHeaderSize );
+ if( nBytes > 5 )
{
- if( pBytes[i] == '%' &&
- pBytes[i+1] == 'P' &&
- pBytes[i+2] == 'D' &&
- pBytes[i+3] == 'F' &&
- pBytes[i+4] == '-' )
+ const sal_Int8* pBytes = aBuf.getConstArray();
+ for( unsigned int i = 0; i < nBytes-5; i++ )
{
- bSuccess = true;
- break;
+ if( pBytes[i] == '%' &&
+ pBytes[i+1] == 'P' &&
+ pBytes[i+2] == 'D' &&
+ pBytes[i+3] == 'F' &&
+ pBytes[i+4] == '-' )
+ {
+ bSuccess = true;
+ break;
+ }
}
}
- }
- // check for hybrid PDF
- oslFileHandle aFile = NULL;
- if( bSuccess &&
- ( aURL.isEmpty() || !comphelper::isFileUrl(aURL) )
- )
- {
- sal_uInt64 nWritten = 0;
- if( osl_createTempFile( NULL, &aFile, &aURL.pData ) != osl_File_E_None )
- {
- bSuccess = false;
- }
- else
+ // check for hybrid PDF
+ if( bSuccess &&
+ ( aURL.isEmpty() || !comphelper::isFileUrl(aURL) )
+ )
{
+ sal_uInt64 nWritten = 0;
+ if( osl_createTempFile( NULL, &aFile, &aURL.pData ) != osl_File_E_None )
+ {
+ bSuccess = false;
+ }
+ else
+ {
#if OSL_DEBUG_LEVEL > 1
- OSL_TRACE( "created temp file %s\n",
- OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() );
+ OSL_TRACE( "created temp file %s\n",
+ OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() );
#endif
- osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
+ osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
- OSL_ENSURE( nWritten == nBytes, "writing of header bytes failed" );
+ OSL_ENSURE( nWritten == nBytes, "writing of header bytes failed" );
- if( nWritten == nBytes )
- {
- const sal_uInt32 nBufSize = 4096;
- aBuf = uno::Sequence<sal_Int8>(nBufSize);
- // copy the bytes
- do
+ if( nWritten == nBytes )
{
- nBytes = xInput->readBytes( aBuf, nBufSize );
- if( nBytes > 0 )
+ const sal_uInt32 nBufSize = 4096;
+ aBuf = uno::Sequence<sal_Int8>(nBufSize);
+ // copy the bytes
+ do
{
- osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
- if( nWritten != nBytes )
+ nBytes = xInput->readBytes( aBuf, nBufSize );
+ if( nBytes > 0 )
{
- bSuccess = false;
- break;
+ osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
+ if( nWritten != nBytes )
+ {
+ bSuccess = false;
+ break;
+ }
}
- }
- } while( nBytes == nBufSize );
+ } while( nBytes == nBufSize );
+ }
}
+ osl_closeFile( aFile );
}
- osl_closeFile( aFile );
+ } catch (css::io::IOException & e) {
+ SAL_WARN("sdext.pdfimport", "caught IOException " + e.Message);
+ return OUString();
}
OUString aEmbedMimetype;
xEmbedStream = getAdditionalStream( aURL, aEmbedMimetype, aPwd, m_xContext, rFilterData, false );
commit 90b0a547920972443f2eea49f9643c6658f040e4
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Sep 10 16:38:26 2015 +0200
Drop no-op skipBytes(0) call
Change-Id: Ieb8c588c8db82a0f1e671e4966d69d87d18997e7
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index f4732d2..4b62de5 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -2280,7 +2280,6 @@ void SfxMedium::GetMedium_Impl()
if ( pImp->m_xInputStreamToLoadFrom.is() )
{
pImp->xInputStream = pImp->m_xInputStreamToLoadFrom;
- pImp->xInputStream->skipBytes(0);
if (pImp->m_bInputStreamIsReadOnly)
GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
}
More information about the Libreoffice-commits
mailing list