Kaydet (Commit) 8ac129a5 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Handle IOException during filter detection

Change-Id: Ie2b8b65f0f2b7b34efbba478a7ccda7ef3719bd6
üst 90b0a547
...@@ -360,32 +360,36 @@ OUString SAL_CALL SVGFilter::detect(Sequence<PropertyValue>& rDescriptor) throw ...@@ -360,32 +360,36 @@ OUString SAL_CALL SVGFilter::detect(Sequence<PropertyValue>& rDescriptor) throw
if (!xInput.is()) if (!xInput.is())
return OUString(); return OUString();
if (isStreamGZip(xInput)) try {
{ if (isStreamGZip(xInput))
boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInput, true )); {
if(!aStream.get()) boost::scoped_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInput, true ));
return OUString(); if(!aStream.get())
return OUString();
SvStream* pMemoryStream = new SvMemoryStream;
uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY); SvStream* pMemoryStream = new SvMemoryStream;
if (!xSeek.is()) uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY);
return OUString(); if (!xSeek.is())
xSeek->seek(0); return OUString();
xSeek->seek(0);
ZCodec aCodec;
aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true); ZCodec aCodec;
aCodec.Decompress(*aStream.get(), *pMemoryStream); aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
aCodec.EndCompression(); aCodec.Decompress(*aStream.get(), *pMemoryStream);
pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN); aCodec.EndCompression();
uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true)); pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN);
uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
if (xDecompressedInput.is() && isStreamSvg(xDecompressedInput))
return OUString(constFilterName); if (xDecompressedInput.is() && isStreamSvg(xDecompressedInput))
} return OUString(constFilterName);
else }
{ else
if (isStreamSvg(xInput)) {
return OUString(constFilterName); if (isStreamSvg(xInput))
return OUString(constFilterName);
}
} catch (css::io::IOException & e) {
SAL_WARN("filter", "caught IOException " + e.Message);
} }
return OUString(); return OUString();
} }
......
...@@ -229,73 +229,78 @@ OUString SAL_CALL PDFDetector::detect( uno::Sequence< beans::PropertyValue >& rF ...@@ -229,73 +229,78 @@ OUString SAL_CALL PDFDetector::detect( uno::Sequence< beans::PropertyValue >& rF
} }
if( xInput.is() ) if( xInput.is() )
{ {
uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY ); oslFileHandle aFile = NULL;
if( xSeek.is() ) try {
xSeek->seek( 0 ); uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
// read the first 1024 byte (see PDF reference implementation note 12) if( xSeek.is() )
const sal_Int32 nHeaderSize = 1024; xSeek->seek( 0 );
uno::Sequence< sal_Int8 > aBuf( nHeaderSize ); // read the first 1024 byte (see PDF reference implementation note 12)
sal_uInt64 nBytes = 0; const sal_Int32 nHeaderSize = 1024;
nBytes = xInput->readBytes( aBuf, nHeaderSize ); uno::Sequence< sal_Int8 > aBuf( nHeaderSize );
if( nBytes > 5 ) sal_uInt64 nBytes = 0;
{ nBytes = xInput->readBytes( aBuf, nHeaderSize );
const sal_Int8* pBytes = aBuf.getConstArray(); if( nBytes > 5 )
for( unsigned int i = 0; i < nBytes-5; i++ )
{ {
if( pBytes[i] == '%' && const sal_Int8* pBytes = aBuf.getConstArray();
pBytes[i+1] == 'P' && for( unsigned int i = 0; i < nBytes-5; i++ )
pBytes[i+2] == 'D' &&
pBytes[i+3] == 'F' &&
pBytes[i+4] == '-' )
{ {
bSuccess = true; if( pBytes[i] == '%' &&
break; pBytes[i+1] == 'P' &&
pBytes[i+2] == 'D' &&
pBytes[i+3] == 'F' &&
pBytes[i+4] == '-' )
{
bSuccess = true;
break;
}
} }
} }
}
// check for hybrid PDF // check for hybrid PDF
oslFileHandle aFile = NULL; if( bSuccess &&
if( bSuccess && ( aURL.isEmpty() || !comphelper::isFileUrl(aURL) )
( aURL.isEmpty() || !comphelper::isFileUrl(aURL) ) )
)
{
sal_uInt64 nWritten = 0;
if( osl_createTempFile( NULL, &aFile, &aURL.pData ) != osl_File_E_None )
{
bSuccess = false;
}
else
{ {
sal_uInt64 nWritten = 0;
if( osl_createTempFile( NULL, &aFile, &aURL.pData ) != osl_File_E_None )
{
bSuccess = false;
}
else
{
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
OSL_TRACE( "created temp file %s\n", OSL_TRACE( "created temp file %s\n",
OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() ); OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() );
#endif #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 ) if( nWritten == nBytes )
{
const sal_uInt32 nBufSize = 4096;
aBuf = uno::Sequence<sal_Int8>(nBufSize);
// copy the bytes
do
{ {
nBytes = xInput->readBytes( aBuf, nBufSize ); const sal_uInt32 nBufSize = 4096;
if( nBytes > 0 ) aBuf = uno::Sequence<sal_Int8>(nBufSize);
// copy the bytes
do
{ {
osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten ); nBytes = xInput->readBytes( aBuf, nBufSize );
if( nWritten != nBytes ) if( nBytes > 0 )
{ {
bSuccess = false; osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
break; 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; OUString aEmbedMimetype;
xEmbedStream = getAdditionalStream( aURL, aEmbedMimetype, aPwd, m_xContext, rFilterData, false ); xEmbedStream = getAdditionalStream( aURL, aEmbedMimetype, aPwd, m_xContext, rFilterData, false );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment