summaryrefslogtreecommitdiff
path: root/sdext
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-09-10 16:39:24 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-09-10 16:39:24 +0200
commit8ac129a59b237e561b0884a2643030c2ce1175dd (patch)
treecab8fea097a2d01aa94d7cb224845f811ce92dbb /sdext
parent90b0a547920972443f2eea49f9643c6658f040e4 (diff)
Handle IOException during filter detection
Change-Id: Ie2b8b65f0f2b7b34efbba478a7ccda7ef3719bd6
Diffstat (limited to 'sdext')
-rw-r--r--sdext/source/pdfimport/filterdet.cxx107
1 files changed, 56 insertions, 51 deletions
diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx
index e966529f7eb2..af89ee742ae1 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 );