sc/source/ui/unoobj/scdetect.cxx | 76 ++++++++++++++++----------------------- sd/source/ui/unoidl/sddetect.cxx | 11 +++++ starmath/source/smdetect.cxx | 15 +++++++ 3 files changed, 58 insertions(+), 44 deletions(-)
New commits: commit 27c3b8bca22353dfdcf4c248539a727522fc4e76 Author: Maxim Monastirsky <momonas...@gmail.com> Date: Tue Feb 25 14:16:25 2014 +0200 Don't write compound header to zero length files Change-Id: Ie964ca8b870714d1c3e92469a771fab9a71f0633 Reviewed-on: https://gerrit.libreoffice.org/8220 Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx index 41f3623..d56e4fe 100644 --- a/sc/source/ui/unoobj/scdetect.cxx +++ b/sc/source/ui/unoobj/scdetect.cxx @@ -510,57 +510,47 @@ OUString SAL_CALL ScFilterDetect::detect( uno::Sequence<beans::PropertyValue>& l pFilter = NULL; - pStream->Seek( STREAM_SEEK_TO_END); - sal_Size nSize = pStream->Tell(); - pStream->Seek( 0); - // Do not attempt to create an SotStorage on a - // 0-length stream as that would create the compound - // document header on the stream and effectively write to - // disk! - if (nSize > 0) + const char* pSearchFilterName = NULL; + if (aTypeName == "calc_Lotus") { - const char* pSearchFilterName = NULL; - if (aTypeName == "calc_Lotus") - { - if (!detectThisFormat(*pStream, pLotus) && !detectThisFormat(*pStream, pLotusNew) && !detectThisFormat(*pStream, pLotus2)) - return OUString(); - - pSearchFilterName = pFilterLotus; - } - else if (aTypeName == "calc_QPro") - { - if (!detectThisFormat(*pStream, pQPro)) - return OUString(); - - pSearchFilterName = pFilterQPro6; - } - else if (aTypeName == "calc_SYLK") - { - if (!detectThisFormat(*pStream, pSylk)) - return OUString(); + if (!detectThisFormat(*pStream, pLotus) && !detectThisFormat(*pStream, pLotusNew) && !detectThisFormat(*pStream, pLotus2)) + return OUString(); - pSearchFilterName = pFilterSylk; - } - else if (aTypeName == "calc_DIF") - { - if (!detectThisFormat(*pStream, pDIF1) && !detectThisFormat(*pStream, pDIF2)) - return OUString(); + pSearchFilterName = pFilterLotus; + } + else if (aTypeName == "calc_QPro") + { + if (!detectThisFormat(*pStream, pQPro)) + return OUString(); - pSearchFilterName = pFilterDif; - } - else if (aTypeName == "calc_dBase") - { - if (!lcl_MayBeDBase(*pStream)) - return OUString(); + pSearchFilterName = pFilterQPro6; + } + else if (aTypeName == "calc_SYLK") + { + if (!detectThisFormat(*pStream, pSylk)) + return OUString(); - pSearchFilterName = pFilterDBase; - } + pSearchFilterName = pFilterSylk; + } + else if (aTypeName == "calc_DIF") + { + if (!detectThisFormat(*pStream, pDIF1) && !detectThisFormat(*pStream, pDIF2)) + return OUString(); - if (!pSearchFilterName) + pSearchFilterName = pFilterDif; + } + else if (aTypeName == "calc_dBase") + { + if (!lcl_MayBeDBase(*pStream)) return OUString(); - pFilter = aMatcher.GetFilter4FilterName(OUString::createFromAscii(pSearchFilterName)); + pSearchFilterName = pFilterDBase; } + + if (!pSearchFilterName) + return OUString(); + + pFilter = aMatcher.GetFilter4FilterName(OUString::createFromAscii(pSearchFilterName)); } } } diff --git a/sd/source/ui/unoidl/sddetect.cxx b/sd/source/ui/unoidl/sddetect.cxx index 853c38e..2ec1973 100644 --- a/sd/source/ui/unoidl/sddetect.cxx +++ b/sd/source/ui/unoidl/sddetect.cxx @@ -352,6 +352,17 @@ OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDes pStm = aMedium.GetInStream(); if (!pStm) pFilter = NULL; + + pStm->Seek(STREAM_SEEK_TO_END); + const sal_Size nSize = pStm->Tell(); + pStm->Seek(STREAM_SEEK_TO_BEGIN); + + // Do not attempt to create an SotStorage on a + // 0-length stream as that would create the compound + // document header on the stream and effectively write to + // disk! + if (!nSize) + pFilter = NULL; } if (pFilter && pStm) diff --git a/starmath/source/smdetect.cxx b/starmath/source/smdetect.cxx index d25f0dd..3d23031 100644 --- a/starmath/source/smdetect.cxx +++ b/starmath/source/smdetect.cxx @@ -296,7 +296,20 @@ OUString SAL_CALL SmFilterDetect::detect( Sequence< PropertyValue >& lDescriptor //this approach, to be fixed at a better level than here SvStream *pStrm = aMedium.GetInStream(); aTypeName = OUString(); - if (pStrm && !pStrm->GetError()) + + sal_Size nSize = 0; + if ( pStrm && !pStrm->GetError() ) + { + pStrm->Seek( STREAM_SEEK_TO_END ); + nSize = pStrm->Tell(); + pStrm->Seek( STREAM_SEEK_TO_BEGIN ); + } + + // Do not attempt to create an SotStorage on a + // 0-length stream as that would create the compound + // document header on the stream and effectively write to + // disk! + if ( nSize > 0 ) { SotStorageRef aStorage = new SotStorage ( pStrm, false ); if ( !aStorage->GetError() )
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits