sc/source/ui/unoobj/scdetect.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
New commits: commit 09d98dfe89a651c1b33a07c3d23e20b266d163e7 Author: Eike Rathke <er...@redhat.com> Date: Wed Apr 4 23:39:17 2012 +0200 resolved fdo#46699 do not write compound document header when reading 0-length file Creating an SotStorage with a 0-length stream has the side-effect of creating the compound document (aka OLE storage) header on the stream and effectively writing that to disk, thus garbling the empty file. diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx index 55ae121..1fb1a84 100644 --- a/sc/source/ui/unoobj/scdetect.cxx +++ b/sc/source/ui/unoobj/scdetect.cxx @@ -450,8 +450,17 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) pFilter = 0; if ( pStream ) { - SotStorageRef aStorage = new SotStorage ( pStream, false ); - if ( !aStorage->GetError() ) + 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! + SotStorageRef aStorage; + if (nSize > 0) + aStorage = new SotStorage ( pStream, false ); + if ( aStorage.Is() && !aStorage->GetError() ) { // Excel-5: detect through contained streams // there are some "excel" formats from 3rd party vendors that need to be distinguished @@ -522,7 +531,7 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) } } } - else + else if (nSize > 0) { SvStream &rStr = *pStream; @@ -767,6 +776,13 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) pFilter = pPreselectedFilter; } } + else + { + // 0-length stream, preselected Text/CSV is ok, user + // may want to write to that file later. + if ( pPreselectedFilter->GetFilterName().EqualsAscii(pFilterAscii) ) + pFilter = pPreselectedFilter; + } } } } _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits