summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-04-04 23:39:17 +0200
committerEike Rathke <erack@redhat.com>2012-04-04 23:39:43 +0200
commit09d98dfe89a651c1b33a07c3d23e20b266d163e7 (patch)
tree9a6f267937c7da8be2cdb58e235076e95d77b5e8
parentc770d2c8472402eecbb88ec72885cd9d6447d370 (diff)
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.
-rw-r--r--sc/source/ui/unoobj/scdetect.cxx22
1 files changed, 19 insertions, 3 deletions
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx
index 55ae121ef2d4..1fb1a8444137 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;
+ }
}
}
}