incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1362844 - in /incubator/ooo/trunk/main/sot/source/sdstor: stg.cxx stgavl.cxx stgcache.cxx stgcache.hxx stgdir.cxx stgdir.hxx stgelem.cxx stgelem.hxx stgio.cxx stgole.cxx stgstrms.cxx stgstrms.hxx storinfo.cxx
Date Wed, 18 Jul 2012 10:21:24 GMT
Author: alg
Date: Wed Jul 18 10:21:23 2012
New Revision: 1362844

URL: http://svn.apache.org/viewvc?rev=1362844&view=rev
Log:
some dangers in sot module removed
Patch by: Mikhail Voytenko

Modified:
    incubator/ooo/trunk/main/sot/source/sdstor/stg.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgavl.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgcache.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgcache.hxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgdir.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgdir.hxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgelem.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgelem.hxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgio.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgole.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.cxx
    incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.hxx
    incubator/ooo/trunk/main/sot/source/sdstor/storinfo.cxx

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stg.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stg.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stg.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stg.cxx Wed Jul 18 10:21:23 2012
@@ -103,7 +103,8 @@ const SvStream* OLEStorageBase::GetSvStr
 OLEStorageBase::OLEStorageBase( StgIo* p, StgDirEntry* pe, StreamMode& nMode )
     : nStreamMode( nMode ), pIo( p ), pEntry( pe )
 {
-	p->IncRef();
+    if ( p )
+        p->IncRef();
 	if( pe )
 		pe->nRefCnt++;
 }
@@ -120,21 +121,28 @@ OLEStorageBase::~OLEStorageBase()
 			else
 				pEntry->Close();
 		}
+
+        pEntry = NULL;
 	}
 
 
-	if( !pIo->DecRef() )
+	if( pIo && !pIo->DecRef() )
+    {
 		delete pIo;
+        pIo = NULL;
+    }
 }
 
 // Validate the instance for I/O
 
 sal_Bool OLEStorageBase::Validate_Impl( sal_Bool bWrite ) const
 {
-    if( pEntry
+    if( pIo
+        && pIo->pTOC
+        && pEntry
 		&& !pEntry->bInvalid
         &&  ( !bWrite || !pEntry->bDirect || ( nStreamMode & STREAM_WRITE
) ) )
-		return sal_True;
+            return sal_True;
 	return sal_False;
 }
 
@@ -173,7 +181,7 @@ StorageStream::StorageStream( StgIo* p, 
              : OLEStorageBase( p, q, m_nMode ), nPos( 0L )
 {
     // The dir entry may be 0; this means that the stream is invalid.
-    if( q )
+    if( q && p )
 	{
 		if( q->nRefCnt == 1 )
 		{
@@ -274,14 +282,21 @@ sal_Bool StorageStream::Commit()
 
 sal_Bool StorageStream::Revert()
 {
-	pEntry->Revert();
-	pIo->MoveError( *this );
-	return Good();
+    sal_Bool bResult = sal_False;
+
+    if ( Validate() )
+    {
+        pEntry->Revert();
+        pIo->MoveError( *this );
+        bResult = Good();
+    }
+
+    return bResult;
 }
 
 sal_Bool StorageStream::CopyTo( BaseStorageStream* pDest )
 {
-    if( !Validate() || !pDest->Validate( sal_True ) || Equals( *pDest ) )
+    if( !Validate() || !pDest || !pDest->Validate( sal_True ) || Equals( *pDest ) )
 		return sal_False;
     pEntry->Copy( *pDest );
 	pDest->Commit();
@@ -341,14 +356,20 @@ sal_Bool Storage::IsStorageFile( const S
 
 sal_Bool Storage::IsStorageFile( SvStream* pStream )
 {
-    StgHeader aHdr;
-    sal_uLong nPos = pStream->Tell();
-    sal_Bool bRet = ( aHdr.Load( *pStream ) && aHdr.Check() );
-
-	// It's not a stream error if it is too small for a OLE storage header
-	if ( pStream->GetErrorCode() == ERRCODE_IO_CANTSEEK )
-		pStream->ResetError();
-    pStream->Seek( nPos );
+    sal_Bool bRet = sal_False;
+
+    if ( pStream )
+    {
+        StgHeader aHdr;
+        sal_uLong nPos = pStream->Tell();
+        bRet = ( aHdr.Load( *pStream ) && aHdr.Check() );
+
+        // It's not a stream error if it is too small for a OLE storage header
+        if ( pStream->GetErrorCode() == ERRCODE_IO_CANTSEEK )
+            pStream->ResetError();
+        pStream->Seek( nPos );
+    }
+
     return bRet;
 }
 
@@ -463,7 +484,9 @@ void Storage::Init( sal_Bool bCreate )
 	pEntry = NULL;
 	sal_Bool bHdrLoaded = sal_False;
     bIsRoot = sal_True;
-	if( pIo->Good() )
+
+    OSL_ENSURE( pIo, "The pointer may not be empty at this point!" );
+	if( pIo->Good() && pIo->GetStrm() )
 	{
 		sal_uLong nSize = pIo->GetStrm()->Seek( STREAM_SEEK_TO_END );
 		pIo->GetStrm()->Seek( 0L );
@@ -484,7 +507,7 @@ void Storage::Init( sal_Bool bCreate )
 	// the file is empty
 	if( !bHdrLoaded )
 		pIo->Init();
-    if( pIo->Good() )
+    if( pIo->Good() && pIo->pTOC )
 	{
         pEntry = pIo->pTOC->GetRoot();
 		pEntry->nRefCnt++;
@@ -539,7 +562,7 @@ const String& Storage::GetName() const
 
 void Storage::FillInfoList( SvStorageInfoList* pList ) const
 {
-	if( Validate() )
+	if( Validate() && pList )
     {
         StgIterator aIter( *pEntry );
         StgDirEntry* p = aIter.First();
@@ -739,21 +762,24 @@ sal_Bool Storage::CopyTo( const String& 
             BaseStorage* p1 = OpenStorage( rElem, INTERNAL_MODE );
             BaseStorage* p2 = pDest->OpenOLEStorage( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL,
pEntry->bDirect );
 
-			sal_uLong nTmpErr = p2->GetError();
-			if( !nTmpErr )
-			{
-            	p2->SetClassId( p1->GetClassId() );
-            	p1->CopyTo( p2 );
-				SetError( p1->GetError() );
-
-				nTmpErr = p2->GetError();
-				if( !nTmpErr )
-					p2->Commit();
-				else
-					pDest->SetError( nTmpErr );
-			}
-			else
-				pDest->SetError( nTmpErr );
+            if ( p2 )
+            {
+                sal_uLong nTmpErr = p2->GetError();
+                if( !nTmpErr )
+                {
+                    p2->SetClassId( p1->GetClassId() );
+                    p1->CopyTo( p2 );
+                    SetError( p1->GetError() );
+
+                    nTmpErr = p2->GetError();
+                    if( !nTmpErr )
+                        p2->Commit();
+                    else
+                        pDest->SetError( nTmpErr );
+                }
+                else
+                    pDest->SetError( nTmpErr );
+            }
 
 			delete p1;
 			delete p2;
@@ -765,20 +791,23 @@ sal_Bool Storage::CopyTo( const String& 
             BaseStorageStream* p1 = OpenStream( rElem, INTERNAL_MODE );
             BaseStorageStream* p2 = pDest->OpenStream( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL,
pEntry->bDirect );
 
-			sal_uLong nTmpErr = p2->GetError();
-			if( !nTmpErr )
-			{
-				p1->CopyTo( p2 );
-				SetError( p1->GetError() );
-
-				nTmpErr = p2->GetError();
-				if( !nTmpErr )
-					p2->Commit();
-				else
-					pDest->SetError( nTmpErr );
-			}
-			else
-				pDest->SetError( nTmpErr );
+            if ( p2 )
+            {
+                sal_uLong nTmpErr = p2->GetError();
+                if( !nTmpErr )
+                {
+                    p1->CopyTo( p2 );
+                    SetError( p1->GetError() );
+
+                    nTmpErr = p2->GetError();
+                    if( !nTmpErr )
+                        p2->Commit();
+                    else
+                        pDest->SetError( nTmpErr );
+                }
+                else
+                    pDest->SetError( nTmpErr );
+            }
 
 			delete p1;
 			delete p2;
@@ -1036,17 +1065,23 @@ sal_Bool Storage::ValidateFAT()
 
 void Storage::SetDirty()
 {
-    pEntry->SetDirty();
+    if ( pEntry )
+        pEntry->SetDirty();
 }
 
 void Storage::SetClassId( const ClsId& rId )
 {
-    pEntry->aEntry.SetClassId( rId );
+    if ( pEntry )
+        pEntry->aEntry.SetClassId( rId );
 }
 
 const ClsId& Storage::GetClassId() const
 {
-    return pEntry->aEntry.GetClassId();
+    if ( pEntry )
+        return pEntry->aEntry.GetClassId();
+
+    static ClsId aDummyId = {0,0,0,0,0,0,0,0,0,0,0};
+    return aDummyId;
 }
 
 const SvStream* Storage::GetSvStream() const

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgavl.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgavl.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgavl.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgavl.cxx Wed Jul 18 10:21:23 2012
@@ -24,7 +24,7 @@
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sot.hxx"
 
-
+#include <osl/diagnose.h>
 #include "stgavl.hxx"
 
 StgAvlNode::StgAvlNode()
@@ -41,13 +41,16 @@ StgAvlNode::~StgAvlNode()
 
 StgAvlNode* StgAvlNode::Find( StgAvlNode* pFind )
 {
-    StgAvlNode* p = this;
-    while( p )
+    if ( pFind )
     {
-        short nRes = p->Compare( pFind );
-        if( !nRes )
-            return p;
-        else p = ( nRes < 0 ) ? p->pLeft : p->pRight;
+        StgAvlNode* p = this;
+        while( p )
+        {
+            short nRes = p->Compare( pFind );
+            if( !nRes )
+                return p;
+            else p = ( nRes < 0 ) ? p->pLeft : p->pRight;
+        }
     }
     return NULL;
 }
@@ -61,23 +64,28 @@ short StgAvlNode::Locate
 {
     short nRes = 0;
     StgAvlNode* pCur = this;
+
+    OSL_ENSURE( pPivot && pParent && pPrev, "The pointers may not be NULL!"
);
     *pParent = *pPrev = NULL;
     *pPivot = this;
 
     // search tree for insertion point
-
-    while( pCur != NULL )
+    if ( pFind )
     {
-        // check for pPivot
-        if( pCur->nBalance != 0 )
-            *pPivot = pCur, *pParent = *pPrev;
-        // save pPrev location and see what direction to go
-        *pPrev = pCur;
-        nRes = pCur->Compare( pFind );
-        if( nRes == 0 )
-            break;
-        else pCur = ( nRes < 0 ) ? pCur->pLeft : pCur->pRight;
+        while( pCur != NULL )
+        {
+            // check for pPivot
+            if( pCur->nBalance != 0 )
+                *pPivot = pCur, *pParent = *pPrev;
+            // save pPrev location and see what direction to go
+            *pPrev = pCur;
+            nRes = pCur->Compare( pFind );
+            if( nRes == 0 )
+                break;
+            else pCur = ( nRes < 0 ) ? pCur->pLeft : pCur->pRight;
+        }
     }
+
     return( nRes );
 }
 
@@ -89,8 +97,10 @@ short StgAvlNode::Adjust( StgAvlNode** p
     StgAvlNode* pCur = this;
     short nDelta;
     // no traversing
-    if( pCur == pNew )
+    OSL_ENSURE( pHeavy && pNew, "The pointers is not allowed to be NULL!" );
+    if( pCur == pNew || !pNew )
         return nBalance;
+
     short nRes = Compare( pNew );
     if( nRes > 0 )
     {
@@ -127,6 +137,7 @@ short StgAvlNode::Adjust( StgAvlNode** p
 
 StgAvlNode* StgAvlNode::RotLL()
 {
+    OSL_ENSURE( pLeft, "The pointer is not allowed to be NULL!" );
     StgAvlNode *pHeavy = pLeft;
     pLeft = pHeavy->pRight;
     pHeavy->pRight = this;
@@ -138,7 +149,7 @@ StgAvlNode* StgAvlNode::RotLL()
 
 StgAvlNode* StgAvlNode::RotLR()
 {
-
+    OSL_ENSURE( pLeft && pLeft->pRight, "The pointer is not allowed to be NULL!"
);
     StgAvlNode* pHeavy = pLeft;
     StgAvlNode* pNewRoot = pHeavy->pRight;
 
@@ -170,6 +181,7 @@ StgAvlNode* StgAvlNode::RotLR()
 
 StgAvlNode* StgAvlNode::RotRR()
 {
+    OSL_ENSURE( pRight, "The pointer is not allowed to be NULL!" );
     StgAvlNode* pHeavy = pRight;
     pRight = pHeavy->pLeft;
     pHeavy->pLeft = this;
@@ -181,6 +193,7 @@ StgAvlNode* StgAvlNode::RotRR()
 
 StgAvlNode* StgAvlNode::RotRL()
 {
+    OSL_ENSURE( pRight && pRight->pLeft, "The pointer is not allowed to be NULL!"
);
     StgAvlNode* pHeavy = pRight;
     StgAvlNode* pNewRoot = pHeavy->pLeft;
     pHeavy->pLeft = pNewRoot->pRight;
@@ -210,7 +223,7 @@ StgAvlNode* StgAvlNode::RotRL()
 
 StgAvlNode* StgAvlNode::Rem( StgAvlNode** p, StgAvlNode* pDel, sal_Bool bPtrs )
 {
-    if( *p )
+    if( p && *p && pDel )
     {
         StgAvlNode* pCur = *p;
         short nRes = bPtrs ? short( pCur == pDel ) : short(pCur->Compare( pDel ));
@@ -264,14 +277,11 @@ StgAvlNode* StgAvlNode::Rem( StgAvlNode*
 
 void StgAvlNode::StgEnum( short& n )
 {
-    if( this )
-    {
-        if( pLeft )
-            pLeft->StgEnum( n );
-        nId = n++;
-        if( pRight )
-            pRight->StgEnum( n );
-    }
+    if( pLeft )
+        pLeft->StgEnum( n );
+    nId = n++;
+    if( pRight )
+        pRight->StgEnum( n );
 }
 
 // Add node to AVL tree.
@@ -280,6 +290,9 @@ void StgAvlNode::StgEnum( short& n )
 sal_Bool StgAvlNode::Insert( StgAvlNode** pRoot, StgAvlNode* pIns )
 {
     StgAvlNode* pPivot, *pHeavy, *pNewRoot, *pParent, *pPrev;
+    if ( !pRoot )
+        return sal_False;
+
     // special case - empty tree
     if( *pRoot == NULL )
     {
@@ -290,6 +303,8 @@ sal_Bool StgAvlNode::Insert( StgAvlNode*
     short nRes = (*pRoot)->Locate( pIns, &pPivot, &pParent, &pPrev );
     if( !nRes )
         return sal_False;
+    OSL_ENSURE( pPivot && pPrev, "The pointers may not be NULL!" );
+
     // add new node
     if( nRes < 0 )
         pPrev->pLeft = pIns;
@@ -327,6 +342,9 @@ sal_Bool StgAvlNode::Insert( StgAvlNode*
 
 sal_Bool StgAvlNode::Remove( StgAvlNode** pRoot, StgAvlNode* pDel, sal_Bool bDel )
 {
+    if ( !pRoot )
+        return sal_False;
+
     // special case - empty tree
     if( *pRoot == NULL )
         return sal_False;
@@ -357,6 +375,9 @@ sal_Bool StgAvlNode::Remove( StgAvlNode*
 sal_Bool StgAvlNode::Move
 	( StgAvlNode** pRoot1, StgAvlNode** pRoot2, StgAvlNode* pMove )
 {
+    if ( !pRoot1 )
+        return sal_False;
+
     // special case - empty tree
     if( *pRoot1 == NULL )
         return sal_False;

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgcache.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgcache.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgcache.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgcache.cxx Wed Jul 18 10:21:23 2012
@@ -67,6 +67,7 @@ typedef std::hash_map
 
 StgPage::StgPage( StgCache* p, short n )
 {
+    OSL_ENSURE( n >= 512, "Unexpected page size is provided!" );
     pCache = p;
     nData  = n;
     bDirty = sal_False;
@@ -130,11 +131,15 @@ StgCache::~StgCache()
 
 void StgCache::SetPhysPageSize( short n )
 {
-    nPageSize = n;
-    sal_uLong nPos = pStrm->Tell();
-    sal_uLong nFileSize = pStrm->Seek( STREAM_SEEK_TO_END );
-    nPages = lcl_GetPageCount( nFileSize, nPageSize );
-    pStrm->Seek( nPos );
+    OSL_ENSURE( n >= 512, "Unexpecte page size is provided!" );
+    if ( n >= 512 )
+    {
+        nPageSize = n;
+        sal_uLong nPos = pStrm->Tell();
+        sal_uLong nFileSize = pStrm->Seek( STREAM_SEEK_TO_END );
+        nPages = lcl_GetPageCount( nFileSize, nPageSize );
+        pStrm->Seek( nPos );
+    }
 }
 
 // Create a new cache element
@@ -188,19 +193,24 @@ StgPage* StgCache::Create( sal_Int32 nPg
 
 void StgCache::Erase( StgPage* pElem )
 {
-	//remove from LRU
-    pElem->pNext1->pLast1 = pElem->pLast1;
-    pElem->pLast1->pNext1 = pElem->pNext1;
-    if( pCur == pElem )
-        pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
-	if( pLRUCache )
-		((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
-	// remove from Sorted
-    pElem->pNext2->pLast2 = pElem->pLast2;
-    pElem->pLast2->pNext2 = pElem->pNext2;
-    if( pElem1 == pElem )
-        pElem1 = ( pElem->pNext2 == pElem ) ? NULL : pElem->pNext2;
-    delete pElem;
+    OSL_ENSURE( pElem, "The pointer should not be NULL!" );
+    if ( pElem )
+    {
+        OSL_ENSURE( pElem->pNext1 && pElem->pLast1, "The pointers may not be
NULL!" );
+        //remove from LRU
+        pElem->pNext1->pLast1 = pElem->pLast1;
+        pElem->pLast1->pNext1 = pElem->pNext1;
+        if( pCur == pElem )
+            pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
+        if( pLRUCache )
+            ((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
+        // remove from Sorted
+        pElem->pNext2->pLast2 = pElem->pLast2;
+        pElem->pLast2->pNext2 = pElem->pNext2;
+        if( pElem1 == pElem )
+            pElem1 = ( pElem->pNext2 == pElem ) ? NULL : pElem->pNext2;
+        delete pElem;
+    }
 }
 
 // remove all cache elements without flushing them
@@ -232,9 +242,11 @@ StgPage* StgCache::Find( sal_Int32 nPage
 	{
 		// page found
 	    StgPage* pFound = (*aIt).second;
+        OSL_ENSURE( pFound, "The pointer may not be NULL!" );
 
 		if( pFound != pCur )
 		{
+            OSL_ENSURE( pFound->pNext1 && pFound->pLast1, "The pointers may
not be NULL!" );
 			// remove from LRU
 			pFound->pNext1->pLast1 = pFound->pLast1;
 			pFound->pLast1->pNext1 = pFound->pNext1;
@@ -281,7 +293,10 @@ StgPage* StgCache::Copy( sal_Int32 nNew,
         // old page: we must have this data!
         StgPage* q = Get( nOld, sal_True );
         if( q )
+        {
+            OSL_ENSURE( p->nData == q->nData, "Unexpected page size!" );
             memcpy( p->pData, q->pData, p->nData );
+        }
     }
     p->SetDirty();
     return p;
@@ -456,11 +471,15 @@ sal_Bool StgCache::Read( sal_Int32 nPage
 
 sal_Bool StgCache::Write( sal_Int32 nPage, void* pBuf, sal_Int32 nPg )
 {
-    if( Good() )
+    if( Good() ) 
     {
         sal_uLong nPos = Page2Pos( nPage );
-        sal_uLong nBytes = nPg * nPageSize;
+        sal_uLong nBytes = 0;
+        if ( SAL_MAX_INT32 / nPg > nPageSize )
+            nBytes = nPg * nPageSize;
+
         // fixed address and size for the header
+        // nPageSize must be >= 512, otherwise the header can not be written here, we
check it on import
         if( nPage == -1 )
             nPos = 0L, nBytes = 512;
         if( pStrm->Tell() != nPos )

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgcache.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgcache.hxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgcache.hxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgcache.hxx Wed Jul 18 10:21:23 2012
@@ -71,7 +71,7 @@ public:
 	SvStream* GetStrm()	  				{ return pStrm;  	}
 	void  SetStrm( SvStream*, sal_Bool );
 	void  SetStrm( UCBStorageStream* );
-	sal_Bool  IsWritable()					{ return pStrm->IsWritable(); }
+	sal_Bool  IsWritable()					{ return ( pStrm && pStrm->IsWritable() ); }
 	sal_Bool  Good()						{ return sal_Bool( nError == SVSTREAM_OK ); }
 	sal_Bool  Bad()                         { return sal_Bool( nError != SVSTREAM_OK ); }
 	sal_uLong GetError()					{ return nError; 	}

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgdir.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgdir.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgdir.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgdir.cxx Wed Jul 18 10:21:23 2012
@@ -50,9 +50,9 @@
 // Problem der Implementation: Keine Hierarchischen commits. Daher nur
 // insgesamt transaktionsorientert oder direkt.
 
-StgDirEntry::StgDirEntry( const void* pFrom, sal_Bool * pbOk ) : StgAvlNode()
+StgDirEntry::StgDirEntry( const void* pBuffer, sal_uInt32 nBufferLen, sal_Bool * pbOk ) :
StgAvlNode()
 {
-	*pbOk = aEntry.Load( pFrom );
+	*pbOk = aEntry.Load( pBuffer, nBufferLen );
 
 	InitMembers();
 }
@@ -99,8 +99,13 @@ StgDirEntry::~StgDirEntry()
 
 short StgDirEntry::Compare( const StgAvlNode* p ) const
 {
-    const StgDirEntry* pEntry = (const StgDirEntry*) p;
-    return aEntry.Compare( pEntry->aEntry );
+    short nResult = -1;
+    if ( p )
+    {
+        const StgDirEntry* pEntry = (const StgDirEntry*) p;
+        nResult = aEntry.Compare( pEntry->aEntry );
+    }
+    return nResult;
 }
 
 // Enumerate the entry numbers.
@@ -260,9 +265,9 @@ void StgDirEntry::OpenStream( StgIo& rIo
 	sal_Int32 nThreshold = (sal_uInt16) rIo.aHdr.GetThreshold();
 	delete pStgStrm;
 	if( !bForceBig && aEntry.GetSize() < nThreshold )
-		pStgStrm = new StgSmallStrm( rIo, this );
+		pStgStrm = new StgSmallStrm( rIo, *this );
 	else
-		pStgStrm = new StgDataStrm( rIo, this );
+		pStgStrm = new StgDataStrm( rIo, *this );
 	if( bInvalid && aEntry.GetSize() )
 	{
 		// This entry has invalid data, so delete that data
@@ -320,6 +325,10 @@ sal_Bool StgDirEntry::SetSize( sal_Int32
 	}
 	else
 	{
+        OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+        if ( !pStgStrm )
+            return sal_False;
+
 		sal_Bool bRes = sal_False;
 		StgIo& rIo = pStgStrm->GetIo();
 		sal_Int32 nThreshold = rIo.aHdr.GetThreshold();
@@ -399,6 +408,10 @@ sal_Int32 StgDirEntry::Seek( sal_Int32 n
 	}
 	else
 	{
+        OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+        if ( !pStgStrm )
+            return nPos;
+
 		sal_Int32 nSize = aEntry.GetSize();
 
 		if( nNew < 0 )
@@ -418,6 +431,7 @@ sal_Int32 StgDirEntry::Seek( sal_Int32 n
 		pStgStrm->Pos2Page( nNew );
 		nNew = pStgStrm->GetPos();
 	}
+
 	return nPos = nNew;
 }
 
@@ -432,7 +446,14 @@ sal_Int32 StgDirEntry::Read( void* p, sa
 	else if( pCurStrm )
 		nLen = pCurStrm->Read( p, nLen );
 	else
+    {
+        OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+        if ( !pStgStrm )
+            return 0;
+
 		nLen = pStgStrm->Read( p, nLen );
+    }
+
 	nPos += nLen;
 	return nLen;
 }
@@ -450,6 +471,11 @@ sal_Int32 StgDirEntry::Write( const void
 	// Is this stream opened in transacted mode? Do we have to make a copy?
 	if( !bDirect && !pTmpStrm && !Strm2Tmp() )
 		return 0;
+
+    OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+    if ( !pStgStrm )
+        return 0;
+
 	if( pTmpStrm )
 	{
 		nLen = pTmpStrm->Write( p, nLen );
@@ -631,6 +657,10 @@ sal_Bool StgDirEntry::Strm2Tmp()
 			{
 				if( n )
 				{
+                    OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+                    if ( !pStgStrm )
+                        return sal_False;
+
 					sal_uInt8 aTempBytes[ 4096 ];
 					void* p = static_cast<void*>( aTempBytes );
 					pStgStrm->Pos2Page( 0L );
@@ -652,9 +682,13 @@ sal_Bool StgDirEntry::Strm2Tmp()
 			else
 				n = 1;
 		}
+
 		if( n )
 		{
-			pStgStrm->GetIo().SetError( pTmpStrm->GetError() );
+            OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+            if ( pStgStrm )
+                pStgStrm->GetIo().SetError( pTmpStrm->GetError() );
+
 			delete pTmpStrm;
 			pTmpStrm = NULL;
 			return sal_False;
@@ -672,6 +706,9 @@ sal_Bool StgDirEntry::Tmp2Strm()
 		pTmpStrm = pCurStrm, pCurStrm = NULL;
 	if( pTmpStrm )
 	{
+        OSL_ENSURE( pStgStrm, "The pointer may not be NULL!" );
+        if ( !pStgStrm )
+            return sal_False;
 		sal_uLong n = pTmpStrm->GetSize();
 		StgStrm* pNewStrm;
 		StgIo& rIo = pStgStrm->GetIo();
@@ -809,7 +846,7 @@ void StgDirStrm::SetupEntry( sal_Int32 n
     if( p )
     {
         sal_Bool bOk(sal_False);
-        StgDirEntry* pCur = new StgDirEntry( p, &bOk );
+        StgDirEntry* pCur = new StgDirEntry( p, STGENTRY_SIZE, &bOk );
 
         if( !bOk )
         {
@@ -864,6 +901,9 @@ void StgDirStrm::SetupEntry( sal_Int32 n
 sal_Bool StgDirStrm::SetSize( sal_Int32 nBytes )
 {
     // Always allocate full pages
+    if ( nBytes < 0 )
+        nBytes = 0;
+
     nBytes = ( ( nBytes + nPageSize - 1 ) / nPageSize ) * nPageSize;
     return StgStrm::SetSize( nBytes );
 }
@@ -872,7 +912,7 @@ sal_Bool StgDirStrm::SetSize( sal_Int32 
 
 sal_Bool StgDirStrm::Store()
 {
-    if( !pRoot->IsDirty() )
+    if( !pRoot || !pRoot->IsDirty() )
         return sal_True;
 	if( !pRoot->StoreStreams( rIo ) )
 		return sal_False;

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgdir.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgdir.hxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgdir.hxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgdir.hxx Wed Jul 18 10:21:23 2012
@@ -66,7 +66,7 @@ public:
 	sal_Bool		 bDirect; 		  			// sal_True: direct mode
 	sal_Bool         bZombie;                   // sal_True: Removed From StgIo
 	sal_Bool		 bInvalid;					// sal_True: invalid entry
-	StgDirEntry( const void*, sal_Bool * pbOk );
+	StgDirEntry( const void* pBuffer, sal_uInt32 nBufferLen, sal_Bool * pbOk );
 	StgDirEntry( const StgEntry& );
 	~StgDirEntry();
 

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgelem.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgelem.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgelem.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgelem.cxx Wed Jul 18 10:21:23 2012
@@ -74,21 +74,44 @@ SvStream& operator <<( SvStream& r, cons
 ///////////////////////////// class StgHeader ////////////////////////////
 
 StgHeader::StgHeader()
-{
-    memset( this, 0, sizeof( StgHeader ) );
+: nVersion( 0 )
+, nByteOrder( 0 )
+, nPageSize( 0 )
+, nDataPageSize( 0 )
+, bDirty( 0 )
+, nFATSize( 0 )
+, nTOCstrm( 0 )
+, nReserved( 0 )
+, nThreshold( 0 )
+, nDataFAT( 0 )
+, nDataFATSize( 0 )
+, nMasterChain( 0 )
+, nMaster( 0 )
+{
+    memset( cSignature, 0, sizeof( cSignature ) );
+    memset( &aClsId, 0, sizeof( ClsId ) );
+    memset( cReserved, 0, sizeof( cReserved ) );
+    memset( nMasterFAT, 0, sizeof( nMasterFAT ) );
 }
 
 void StgHeader::Init()
 {
-    memset( this, 0, sizeof( StgHeader ) );
     memcpy( cSignature, cStgSignature, 8 );
+    memset( &aClsId, 0, sizeof( ClsId ) );
     nVersion      = 0x0003003B;
     nByteOrder    = 0xFFFE;
     nPageSize     = 9;          // 512 bytes
     nDataPageSize = 6;          // 64 bytes
+    bDirty = 0;
+    memset( cReserved, 0, sizeof( cReserved ) );
+    nFATSize = 0;
+    nTOCstrm = 0;
+    nReserved = 0;
     nThreshold    = 4096;
+    nDataFAT = 0;
 	nDataFATSize  = 0;
     nMasterChain  = STG_EOF;
+
     SetTOCStart( STG_EOF );
     SetDataFATStart( STG_EOF );
     for( short i = 0; i < 109; i++ )
@@ -97,9 +120,15 @@ void StgHeader::Init()
 
 sal_Bool StgHeader::Load( StgIo& rIo )
 {
-	SvStream& r = *rIo.GetStrm();
-    Load( r );
-	return rIo.Good();
+    sal_Bool bResult = sal_False;
+    if ( rIo.GetStrm() )
+    {
+        SvStream& r = *rIo.GetStrm();
+        bResult = Load( r );
+	    bResult = ( bResult && rIo.Good() );
+    }
+
+    return bResult;
 }
 
 sal_Bool StgHeader::Load( SvStream& r )
@@ -122,7 +151,8 @@ sal_Bool StgHeader::Load( SvStream& r )
 	  >> nMaster;					// 48 # of additional master blocks
 	for( short i = 0; i < 109; i++ )
 		r >> nMasterFAT[ i ];
-    return r.GetErrorCode() == ERRCODE_NONE;
+
+    return ( r.GetErrorCode() == ERRCODE_NONE && Check() );
 }
 
 sal_Bool StgHeader::Store( StgIo& rIo )
@@ -161,8 +191,15 @@ sal_Bool StgHeader::Check()
 {
     return sal_Bool( memcmp( cSignature, cStgSignature, 8 ) == 0
             && (short) ( nVersion >> 16 ) == 3 )
+            && nPageSize == 9
             && lcl_wontoverflow(nPageSize)
-            && lcl_wontoverflow(nDataPageSize);
+            && lcl_wontoverflow(nDataPageSize)
+            && nFATSize > 0
+            && nTOCstrm >= 0
+            && nThreshold > 0
+            && ( nDataFAT == -2 || ( nDataFAT >= 0 && nDataFATSize >
0 ) )
+            && ( nMasterChain == -2 || ( nMasterChain >=0 && nMaster >
109 ) )
+            && nMaster >= 0;
 }
 
 sal_Int32 StgHeader::GetFATPage( short n ) const
@@ -251,7 +288,21 @@ static void FromUnicode( String& rName )
 */
 sal_Bool StgEntry::Init()
 {
-    memset( this, 0, sizeof (StgEntry) - sizeof( String ) );
+    memset( nName, 0, sizeof( nName ) );
+    nNameLen = 0;
+    cType = 0;
+    cFlags = 0;
+    nLeft = 0;
+    nRight = 0;
+    nChild = 0;
+	memset( &aClsId, 0, sizeof( aClsId ) );
+    nFlags = 0;
+    nMtime[0] = 0; nMtime[1] = 0;
+    nAtime[0] = 0; nAtime[1] = 0;
+    nPage1 = 0;
+    nSize = 0;
+    nUnknown = 0;
+
     SetLeaf( STG_LEFT,  STG_FREE );
     SetLeaf( STG_RIGHT, STG_FREE );
     SetLeaf( STG_CHILD, STG_FREE );
@@ -358,9 +409,12 @@ short StgEntry::Compare( const StgEntry&
 // These load/store operations are a bit more complicated,
 // since they have to copy their contents into a packed structure.
 
-sal_Bool StgEntry::Load( const void* pFrom )
+sal_Bool StgEntry::Load( const void* pFrom, sal_uInt32 nBufSize )
 {
-	SvMemoryStream r( (sal_Char*) pFrom, 128, STREAM_READ );
+    if ( nBufSize < 128 )
+        return sal_False;
+
+	SvMemoryStream r( (sal_Char*) pFrom, nBufSize, STREAM_READ );
 	for( short i = 0; i < 32; i++ )
 		r >> nName[ i ];			// 00 name as WCHAR
 	r >> nNameLen 					// 40 size of name in bytes including 00H
@@ -382,7 +436,7 @@ sal_Bool StgEntry::Load( const void* pFr
     sal_uInt16 n = nNameLen;
     if( n )
 		n = ( n >> 1 ) - 1;
-	if( n > 31 || (nSize < 0 && cType != STG_STORAGE) )
+	if( n > 31 || (nSize < 0 && cType != STG_STORAGE) || ( nPage1 < 0 &&
nPage1 != -2 ) )
     {
         // the size makes no sence for the substorage
         // TODO/LATER: actually the size should be an unsigned value, but in this case it
would mean a stream of more than 2Gb

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgelem.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgelem.hxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgelem.hxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgelem.hxx Wed Jul 18 10:21:23 2012
@@ -61,6 +61,7 @@ class StgHeader
 	sal_Int32	nMasterFAT[ 109 ];			// 4C first 109 master FAT pages
 public:
 	StgHeader();
+
 	void  Init();						// initialize the header
 	sal_Bool  Load( StgIo& );
     sal_Bool  Load( SvStream& );
@@ -136,7 +137,7 @@ public:
 	void	GetName( String& rName ) const;
 	                                    // fill in the name
 	short	Compare( const StgEntry& ) const;	// compare two entries
-	sal_Bool	Load( const void* );
+	sal_Bool	Load( const void* pBuffer, sal_uInt32 nBufSize );
 	void    Store( void* );
 	StgEntryType GetType() const		{ return (StgEntryType) cType;	}
 	sal_Int32   GetStartPage() const        { return nPage1; }

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgio.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgio.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgio.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgio.cxx Wed Jul 18 10:21:23 2012
@@ -66,6 +66,8 @@ sal_Bool StgIo::Load()
             else
 				return sal_False;
         }
+        else
+            return sal_False;
     }
     return Good();
 }
@@ -99,7 +101,7 @@ void StgIo::SetupStreams()
 		if( pRoot )
 		{
 			pDataFAT = new StgDataStrm( *this, aHdr.GetDataFATStart(), -1 );
-			pDataStrm = new StgDataStrm( *this, pRoot );
+			pDataStrm = new StgDataStrm( *this, *pRoot );
 			pDataFAT->SetIncrement( 1 << aHdr.GetPageSize() );
 			pDataStrm->SetIncrement( GetDataPageSize() );
 			pDataStrm->SetEntry( *pRoot );
@@ -121,7 +123,7 @@ short StgIo::GetDataPageSize()
 sal_Bool StgIo::CommitAll()
 {
 	// Store the data (all streams and the TOC)
-    if( pTOC->Store() )
+    if( pTOC && pTOC->Store() && pDataFAT )
     {
         if( Commit( NULL ) )
         {
@@ -158,7 +160,11 @@ public:
 
 	sal_Int32 GetPageSize() { return nPageSize; }
 	sal_Int32 Count() { return nPages; }
-	sal_Int32 operator[]( sal_Int32 nOffset ) { return pFat[ nOffset ]; }
+	sal_Int32 operator[]( sal_Int32 nOffset )
+    {
+        OSL_ENSURE( nOffset >= 0 && nOffset < nPages, "Unexpected offset!"
);
+        return nOffset >= 0 && nOffset < nPages ? pFat[ nOffset ] : -2;
+    }
 
 	sal_uLong Mark( sal_Int32 nPage, sal_Int32 nCount, sal_Int32 nExpect );
 	sal_Bool HasUnrefChains();
@@ -206,6 +212,8 @@ sal_uLong EasyFat::Mark( sal_Int32 nPage
 	sal_Int32 nCurPage = nPage;
 	while( nCount != 0 )
 	{
+		if( nCurPage < 0 || nCurPage >= nPages )
+			return FAT_OUTOFBOUNDS;
 		pFree[ nCurPage ] = sal_False;
 		nCurPage = pFat[ nCurPage ];
 		//Stream zu lang
@@ -219,9 +227,6 @@ sal_uLong EasyFat::Mark( sal_Int32 nPage
 			nCount = 1;
 		if( nCount != -1 )
 			nCount--;
-		// Naechster Block nicht in der FAT
-		if( nCount && ( nCurPage < 0 || nCurPage >= nPages ) )
-			return FAT_OUTOFBOUNDS;
 	}
 	return FAT_OK;
 }
@@ -265,6 +270,9 @@ sal_uLong Validator::ValidateMasterFATs(
 {
     sal_Int32 nCount = rIo.aHdr.GetFATSize();
     sal_uLong nErr;
+    if ( !rIo.pFAT )
+	    return FAT_INMEMORYERROR;
+
     for( sal_Int32 i = 0; i < nCount; i++ )
     {
         if( ( nErr = aFat.Mark(rIo.pFAT->GetPage( short(i), sal_False ), aFat.GetPageSize(),
-3 )) != FAT_OK )
@@ -273,11 +281,15 @@ sal_uLong Validator::ValidateMasterFATs(
     if( rIo.aHdr.GetMasters() )
         if( ( nErr = aFat.Mark(rIo.aHdr.GetFATChain( ), aFat.GetPageSize(), -4 )) != FAT_OK
)
             return nErr;
+
     return FAT_OK;
 }
 
 sal_uLong Validator::MarkAll( StgDirEntry *pEntry )
 {
+    if ( !pEntry )
+	    return FAT_INMEMORYERROR;
+
 	StgIterator aIter( *pEntry );
 	sal_uLong nErr = FAT_OK;
 	for( StgDirEntry* p = aIter.First(); p ; p = aIter.Next() )
@@ -304,6 +316,9 @@ sal_uLong Validator::MarkAll( StgDirEntr
 
 sal_uLong Validator::ValidateDirectoryEntries()
 {
+    if ( !rIo.pTOC )
+	    return FAT_INMEMORYERROR;
+
 	// Normale DirEntries
 	sal_uLong nErr = MarkAll( rIo.pTOC->GetRoot() );
 	if( nErr != FAT_OK )
@@ -353,7 +368,11 @@ sal_uLong StgIo::ValidateFATs()
 		Validator *pV = new Validator( *this );
 		sal_Bool bRet1 = !pV->IsError(), bRet2 = sal_True ;
 		delete pV;
+
 		SvFileStream *pFileStrm = ( SvFileStream *) GetStrm();
+        if ( !pFileStrm )
+            return FAT_INMEMORYERROR;
+
 		StgIo aIo;
 		if( aIo.Open( pFileStrm->GetFileName(),
 					  STREAM_READ  | STREAM_SHARE_DENYNONE) &&

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgole.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgole.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgole.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgole.cxx Wed Jul 18 10:21:23 2012
@@ -122,37 +122,22 @@ sal_Bool StgCompObjStream::Load()
 		*this >> aClsId;
 		sal_Int32 nLen1 = 0;
 		*this >> nLen1;
-		// higher bits are ignored
-		nLen1 &= 0xFFFF;
-		sal_Char* p = new sal_Char[ (sal_uInt16) nLen1 ];
-		if( Read( p, nLen1 ) == (sal_uLong) nLen1 )
-		{
-			aUserName = nLen1 ? String( p, gsl_getSystemTextEncoding() ) : String();
-/*			// Now we can read the CB format
-			sal_Int32 nLen2 = 0;
-			*this >> nLen2;
-			if( nLen2 > 0 )
-			{
-				// get a string name
-				if( nLen2 > nLen1 )
-					delete p, p = new char[ nLen2 ];
-				if( Read( p, nLen2 ) == (sal_uLong) nLen2 && nLen2 )
-					nCbFormat = Exchange::RegisterFormatName( String( p ) );
-				else
-					SetError( SVSTREAM_GENERALERROR );
-			}
-			else if( nLen2 == -1L )
-				// Windows clipboard format
-				*this >> nCbFormat;
-			else
-				// unknown identifier
-				SetError( SVSTREAM_GENERALERROR );
-*/
-			nCbFormat = ReadClipboardFormat( *this );
-		}
-		else
-			SetError( SVSTREAM_GENERALERROR );
-        delete [] p;
+        if ( nLen1 > 0 )
+        {
+            // higher bits are ignored
+            sal_uLong nStrLen = ::std::min( nLen1, (sal_Int32)0xFFFE );
+
+            sal_Char* p = new sal_Char[ nStrLen+1 ];
+            p[nStrLen] = 0;
+            if( Read( p, nStrLen ) == nStrLen )
+            {
+                aUserName = nStrLen ? String( p, gsl_getSystemTextEncoding() ) : String();
+                nCbFormat = ReadClipboardFormat( *this );
+            }
+            else
+                SetError( SVSTREAM_GENERALERROR );
+            delete [] p;
+        }
 	}
 	return sal_Bool( GetError() == SVSTREAM_OK );
 }

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.cxx Wed Jul 18 10:21:23 2012
@@ -78,7 +78,7 @@ sal_Int32 StgFAT::GetNextPage( sal_Int32
 {
     if( nPg >= 0 )
     {
-        StgPage* pPg = GetPhysPage( nPg << 2 );
+      StgPage* pPg = GetPhysPage( nPg << 2 );
         nPg = pPg ? pPg->GetPage( nOffset >> 2 ) : STG_EOF;
     }
     return nPg;
@@ -266,19 +266,22 @@ sal_Int32 StgFAT::AllocPages( sal_Int32 
 sal_Bool StgFAT::InitNew( sal_Int32 nPage1 )
 {
     sal_Int32 n = ( ( rStrm.GetSize() >> 2 ) - nPage1 ) / nEntries;
-	while( n-- )
+    if ( n > 0 )
     {
-        StgPage* pPg = NULL;
-        // Position within the underlying stream
-        // use the Pos2Page() method of the stream
-        rStrm.Pos2Page( nPage1 << 2 );
-        // Initialize the page
-        pPg = rStrm.GetIo().Copy( rStrm.GetPage(), STG_FREE );
-		if ( !pPg )
-			return sal_False;
-        for( short i = 0; i < nEntries; i++ )
-            pPg->SetPage( i, STG_FREE );
-		nPage1++;
+        while( n-- )
+        {
+            StgPage* pPg = NULL;
+            // Position within the underlying stream
+            // use the Pos2Page() method of the stream
+            rStrm.Pos2Page( nPage1 << 2 );
+            // Initialize the page
+            pPg = rStrm.GetIo().Copy( rStrm.GetPage(), STG_FREE );
+            if ( !pPg )
+                return sal_False;
+            for( short i = 0; i < nEntries; i++ )
+                pPg->SetPage( i, STG_FREE );
+            nPage1++;
+        }
     }
     return sal_True;
 }
@@ -337,6 +340,9 @@ void StgStrm::SetEntry( StgDirEntry& r )
 
 sal_Bool StgStrm::Pos2Page( sal_Int32 nBytePos )
 {
+    if ( !pFat )
+        return sal_False;
+
     sal_Int32 nRel, nBgn;
     // Values < 0 seek to the end
     if( nBytePos < 0 || nBytePos >= nSize )
@@ -401,6 +407,9 @@ StgPage* StgStrm::GetPhysPage( sal_Int32
 
 sal_Bool StgStrm::Copy( sal_Int32 nFrom, sal_Int32 nBytes )
 {
+    if ( !pFat )
+        return sal_False;
+
     sal_Int32 nTo = nStart;
     sal_Int32 nPgs = ( nBytes + nPageSize - 1 ) / nPageSize;
     while( nPgs-- )
@@ -427,6 +436,9 @@ sal_Bool StgStrm::Copy( sal_Int32 nFrom,
 
 sal_Bool StgStrm::SetSize( sal_Int32 nBytes )
 {
+    if ( nBytes < 0 || !pFat )
+        return sal_False;
+
     // round up to page size
     sal_Int32 nOld = ( ( nSize + nPageSize - 1 ) / nPageSize ) * nPageSize;
     sal_Int32 nNew = ( ( nBytes + nPageSize - 1 ) / nPageSize ) * nPageSize;
@@ -498,6 +510,7 @@ sal_Bool StgFATStrm::Pos2Page( sal_Int32
 
 StgPage* StgFATStrm::GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce )
 {
+    OSL_ENSURE( nBytePos >= 0, "The value may not be negative!" );
     return rIo.Get( nBytePos / ( nPageSize >> 2 ), bForce );
 }
 
@@ -505,6 +518,7 @@ StgPage* StgFATStrm::GetPhysPage( sal_In
 
 sal_Int32 StgFATStrm::GetPage( short nOff, sal_Bool bMake, sal_uInt16 *pnMasterAlloc )
 {
+    OSL_ENSURE( nOff >= 0, "The offset may not be negative!" );
     if( pnMasterAlloc ) *pnMasterAlloc = 0;
     if( nOff < rIo.aHdr.GetFAT1Size() )
         return rIo.aHdr.GetFATPage( nOff );
@@ -579,6 +593,7 @@ sal_Int32 StgFATStrm::GetPage( short nOf
 
 sal_Bool StgFATStrm::SetPage( short nOff, sal_Int32 nNewPage )
 {
+    OSL_ENSURE( nOff >= 0, "The offset may not be negative!" );
     sal_Bool bRes = sal_True;
     if( nOff < rIo.aHdr.GetFAT1Size() )
         rIo.aHdr.SetFATPage( nOff, nNewPage );
@@ -628,6 +643,9 @@ sal_Bool StgFATStrm::SetPage( short nOff
 
 sal_Bool StgFATStrm::SetSize( sal_Int32 nBytes )
 {
+    if ( nBytes < 0 )
+        return sal_False;
+
     // Set the number of entries to a multiple of the page size
     short nOld = (short) ( ( nSize + ( nPageSize - 1 ) ) / nPageSize );
     short nNew = (short) (
@@ -654,6 +672,7 @@ sal_Bool StgFATStrm::SetSize( sal_Int32 
 
             // find a free page using the FAT allocator
             sal_Int32 n = 1;
+            OSL_ENSURE( pFat, "The pointer is always initializer here!" );
             sal_Int32 nNewPage = pFat->FindBlock( n );
             if( nNewPage == STG_EOF )
 			{
@@ -726,21 +745,25 @@ StgDataStrm::StgDataStrm( StgIo& r, sal_
     Init( nBgn, nLen );
 }
 
-StgDataStrm::StgDataStrm( StgIo& r, StgDirEntry* p ) : StgStrm( r )
+StgDataStrm::StgDataStrm( StgIo& r, StgDirEntry& p ) : StgStrm( r )
 {
-    pEntry = p;
-    Init( p->aEntry.GetLeaf( STG_DATA ),
-          p->aEntry.GetSize() );
+    pEntry = &p;
+    Init( p.aEntry.GetLeaf( STG_DATA ),
+          p.aEntry.GetSize() );
 }
 
 void StgDataStrm::Init( sal_Int32 nBgn, sal_Int32 nLen )
 {
-    pFat = new StgFAT( *rIo.pFAT, sal_True );
+    if ( rIo.pFAT )
+        pFat = new StgFAT( *rIo.pFAT, sal_True );
+
+    OSL_ENSURE( pFat, "The pointer should not be empty!" );
+
     nStart = nPage = nBgn;
     nSize  = nLen;
     nIncr  = 1;
     nOffset = 0;
-    if( nLen < 0 )
+    if( nLen < 0 && pFat )
     {
         // determine the actual size of the stream by scanning
         // the FAT chain and counting the # of pages allocated
@@ -761,6 +784,9 @@ void StgDataStrm::Init( sal_Int32 nBgn, 
 
 sal_Bool StgDataStrm::SetSize( sal_Int32 nBytes )
 {
+    if ( !pFat )
+        return sal_False;
+
     nBytes = ( ( nBytes + nIncr - 1 ) / nIncr ) * nIncr;
     sal_Int32 nOldSz = nSize;
     if( ( nOldSz != nBytes ) )
@@ -866,12 +892,15 @@ sal_Int32 StgDataStrm::Read( void* pBuf,
 
 sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
 {
+    if ( n < 0 )
+        return 0;
+
     sal_Int32 nDone = 0;
     if( ( nPos + n ) > nSize )
 	{
 		sal_Int32 nOld = nPos;
 		if( !SetSize( nPos + n ) )
-            return sal_False;
+            return 0;
 		Pos2Page( nOld );
 	}
     while( n )
@@ -936,17 +965,20 @@ StgSmallStrm::StgSmallStrm( StgIo& r, sa
 	Init( nBgn, nLen );
 }
 
-StgSmallStrm::StgSmallStrm( StgIo& r, StgDirEntry* p ) : StgStrm( r )
+StgSmallStrm::StgSmallStrm( StgIo& r, StgDirEntry& p ) : StgStrm( r )
 {
-    pEntry = p;
-    Init( p->aEntry.GetLeaf( STG_DATA ),
-          p->aEntry.GetSize() );
+    pEntry = &p;
+    Init( p.aEntry.GetLeaf( STG_DATA ),
+          p.aEntry.GetSize() );
 }
 
 void StgSmallStrm::Init( sal_Int32 nBgn, sal_Int32 nLen )
 {
-    pFat = new StgFAT( *rIo.pDataFAT, sal_False );
+    if ( rIo.pDataFAT )
+        pFat = new StgFAT( *rIo.pDataFAT, sal_False );
     pData = rIo.pDataStrm;
+    OSL_ENSURE( pFat && pData, "The pointers should not be empty!" );
+
     nPageSize = rIo.GetDataPageSize();
     nStart =
     nPage  = nBgn;
@@ -971,7 +1003,7 @@ sal_Int32 StgSmallStrm::Read( void* pBuf
             nBytes = (short) n;
         if( nBytes )
         {
-            if( !pData->Pos2Page( nPage * nPageSize + nOffset ) )
+            if( !pData || !pData->Pos2Page( nPage * nPageSize + nOffset ) )
                 break;
             // all reading thru the stream
             short nRes = (short) pData->Read( (sal_uInt8*)pBuf + nDone, nBytes );
@@ -1011,9 +1043,10 @@ sal_Int32 StgSmallStrm::Write( const voi
         {
             // all writing goes thru the stream
             sal_Int32 nDataPos = nPage * nPageSize + nOffset;
-            if( pData->GetSize() < ( nDataPos + nBytes ) )
-                if( !pData->SetSize( nDataPos + nBytes ) )
-                    break;
+            if ( !pData
+              || ( pData->GetSize() < ( nDataPos + nBytes )
+                && !pData->SetSize( nDataPos + nBytes ) ) )
+                break;
             if( !pData->Pos2Page( nDataPos ) )
                 break;
             short nRes = (short) pData->Write( (sal_uInt8*)pBuf + nDone, nBytes );

Modified: incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.hxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.hxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/stgstrms.hxx Wed Jul 18 10:21:23 2012
@@ -120,7 +120,7 @@ class StgDataStrm : public StgStrm		// a
 	void Init( sal_Int32 nBgn, sal_Int32 nLen );
 public:
 	StgDataStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen=-1 );
-	StgDataStrm( StgIo&, StgDirEntry* );
+	StgDataStrm( StgIo&, StgDirEntry& );
 	void* GetPtr( sal_Int32 nPos, sal_Bool bForce, sal_Bool bDirty );
 	void SetIncrement( short n ) { nIncr = n ; }
 	virtual sal_Bool SetSize( sal_Int32 );
@@ -139,7 +139,7 @@ class StgSmallStrm : public StgStrm		// 
 	void Init( sal_Int32 nBgn, sal_Int32 nLen );
 public:
 	StgSmallStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen );
-	StgSmallStrm( StgIo&, StgDirEntry* );
+	StgSmallStrm( StgIo&, StgDirEntry& );
 	virtual sal_Int32 Read( void*, sal_Int32 );
 	virtual sal_Int32 Write( const void*, sal_Int32 );
 	virtual sal_Bool IsSmallStrm() { return sal_True; }

Modified: incubator/ooo/trunk/main/sot/source/sdstor/storinfo.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sot/source/sdstor/storinfo.cxx?rev=1362844&r1=1362843&r2=1362844&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sot/source/sdstor/storinfo.cxx (original)
+++ incubator/ooo/trunk/main/sot/source/sdstor/storinfo.cxx Wed Jul 18 10:21:23 2012
@@ -56,10 +56,11 @@ sal_uLong ReadClipboardFormat( SvStream 
     if( nLen > 0 )
     {
         // get a string name
-        sal_Char * p = new sal_Char[ nLen ];
-        if( rStm.Read( p, nLen ) == (sal_uLong) nLen )
+        sal_Char * p = new( ::std::nothrow ) sal_Char[ nLen ];
+        if( p && rStm.Read( p, nLen ) == (sal_uLong) nLen )
         {
-            nFormat = SotExchange::RegisterFormatName( String::CreateFromAscii( p, short(nLen-1)
) );
+            // take so much from the buffer, as the string supports
+            nFormat = SotExchange::RegisterFormatName( String::CreateFromAscii( p, xub_StrLen(
( nLen - 1 ) & STRING_MAXLEN ) ) );
         }
         else
             rStm.SetError( SVSTREAM_GENERALERROR );



Mime
View raw message