Kaydet (Commit) dc5383e2 authored tarafından Michael Meeks's avatar Michael Meeks

fdo#84229 - don't set error when seeking beyond end of valid data.

XclImpStream and elsewhere does an initial seek to the end, then a
tell to work out the true length of the stream. In order to let us
attempt to rescue data from the beginning of otherwise corrupt /
truncated streams, we should avoid setting an error here.

Interestingly, we also (probably) don't want to return the true length
of the valid data - as this is how SotStorage has worked historically.

Change-Id: Ie0ff0e183220b81871ae3bf83980a24b57ac8694
üst dcf94753
......@@ -357,12 +357,16 @@ void StgStrm::scanBuildPageChainCache(sal_Int32 *pOptionalCalcSize)
//returned second is false if it already exists
if (!nUsedPageNumbers.insert(nBgn).second)
{
SAL_WARN ("sot", "Error: page number " << nBgn << " already in chain for stream");
bError = true;
}
nOptSize += nPageSize;
}
if (bError)
{
SAL_WARN("sot", "returning wrong format error");
if (pOptionalCalcSize)
rIo.SetError( ERRCODE_IO_WRONGFORMAT );
m_aPagesCache.clear();
......@@ -424,11 +428,18 @@ bool StgStrm::Pos2Page( sal_Int32 nBytePos )
if ( nIdx > m_aPagesCache.size() )
{
rIo.SetError( SVSTREAM_FILEFORMAT_ERROR );
SAL_WARN("sot", "seek to index " << nIdx <<
" beyond page cache size " << m_aPagesCache.size());
// fdo#84229 - handle seek to end and back as eg. XclImpStream expects
nIdx = m_aPagesCache.size();
nPage = STG_EOF;
nOffset = nPageSize;
nOffset = 0;
// Intriguingly in the past we didn't reset nPos to match the real
// length of the stream thus: nPos = nPageSize * nIdx; so retain
// this behavior for now.
return false;
}
// special case: seek to 1st byte of new, unallocated page
// (in case the file size is a multiple of the page size)
if( nBytePos == nSize && !nOffset && nIdx > 0 && nIdx == m_aPagesCache.size() )
......
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