Kaydet (Commit) 09d98dfe authored tarafından Eike Rathke's avatar Eike Rathke

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.
üst c770d2c8
...@@ -450,8 +450,17 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) ...@@ -450,8 +450,17 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
pFilter = 0; pFilter = 0;
if ( pStream ) if ( pStream )
{ {
SotStorageRef aStorage = new SotStorage ( pStream, false ); pStream->Seek( STREAM_SEEK_TO_END);
if ( !aStorage->GetError() ) 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 // Excel-5: detect through contained streams
// there are some "excel" formats from 3rd party vendors that need to be distinguished // 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 ) ...@@ -522,7 +531,7 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
} }
} }
} }
else else if (nSize > 0)
{ {
SvStream &rStr = *pStream; SvStream &rStr = *pStream;
...@@ -767,6 +776,13 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream ) ...@@ -767,6 +776,13 @@ static sal_Bool lcl_MayBeDBase( SvStream& rStream )
pFilter = pPreselectedFilter; 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;
}
} }
} }
} }
......
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