[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - 2 commits - sot/qa sot/source
Michael Meeks
michael.meeks at collabora.com
Tue Dec 30 09:48:02 PST 2014
sot/qa/cppunit/data/pass/fdo84229-1.compound |binary
sot/qa/cppunit/test_sot.cxx | 26 ++++++++++++++++++++++++++
sot/source/sdstor/stgstrms.cxx | 15 +++++++++++++--
3 files changed, 39 insertions(+), 2 deletions(-)
New commits:
commit 859b59ce572f5781f3e2fa9ae6416cfd65116ca3
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Tue Dec 30 17:39:58 2014 +0000
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
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index b857c6d..0dbfe36 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -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() )
commit 0376706c11458c269d6736e17367ee3f0404c4e9
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Tue Dec 30 17:38:12 2014 +0000
fdo#84229 - add sot storage unit test.
Change-Id: Ic11c397984602bf8a2e292bc901cd7bf71ad555d
diff --git a/sot/qa/cppunit/data/pass/fdo84229-1.compound b/sot/qa/cppunit/data/pass/fdo84229-1.compound
new file mode 100644
index 0000000..46eb4da
Binary files /dev/null and b/sot/qa/cppunit/data/pass/fdo84229-1.compound differ
diff --git a/sot/qa/cppunit/test_sot.cxx b/sot/qa/cppunit/test_sot.cxx
index c97a86e..92ade70 100644
--- a/sot/qa/cppunit/test_sot.cxx
+++ b/sot/qa/cppunit/test_sot.cxx
@@ -36,9 +36,11 @@ namespace
unsigned int, unsigned int, unsigned int) SAL_OVERRIDE;
void test();
+ void testSize();
CPPUNIT_TEST_SUITE(SotTest);
CPPUNIT_TEST(test);
+ CPPUNIT_TEST(testSize);
CPPUNIT_TEST_SUITE_END();
};
@@ -120,6 +122,30 @@ namespace
OUString());
}
+ void SotTest::testSize()
+ {
+ OUString aURL(getURLFromSrc("/sot/qa/cppunit/data/pass/fdo84229-1.compound"));
+ SvFileStream aStream(aURL, STREAM_READ);
+ SotStorageRef xObjStor = new SotStorage(aStream);
+ CPPUNIT_ASSERT_MESSAGE("sot storage failed to open",
+ xObjStor.Is() && !xObjStor->GetError());
+ SotStorageStreamRef xStream = xObjStor->OpenSotStream("Book");
+ CPPUNIT_ASSERT_MESSAGE("stream failed to open",
+ xStream.Is() && !xObjStor->GetError());
+ CPPUNIT_ASSERT_MESSAGE("error in opened stream", !xStream->GetError());
+ sal_uLong nPos = xStream->GetSize();
+ CPPUNIT_ASSERT_MESSAGE("odd stream length", nPos == 13312);
+
+ xStream->Seek(STREAM_SEEK_TO_END);
+ CPPUNIT_ASSERT_MESSAGE("error seeking to end", !xStream->GetError());
+ // cf. comment in Pos2Page, not extremely intuitive ...
+ CPPUNIT_ASSERT_MESSAGE("stream not at beginning", xStream->Tell() == xStream->GetSize());
+ xStream->Seek(STREAM_SEEK_TO_BEGIN);
+
+ CPPUNIT_ASSERT_MESSAGE("error seeking to beginning", !xStream->GetError());
+ CPPUNIT_ASSERT_MESSAGE("stream not at beginning", xStream->Tell() == 0);
+ }
+
CPPUNIT_TEST_SUITE_REGISTRATION(SotTest);
}
More information about the Libreoffice-commits
mailing list