--- goodies/source/filter.vcl/itiff/itiff.cxx.old	2007-10-16 12:13:42.000000000 +0200
+++ goodies/source/filter.vcl/itiff/itiff.cxx	2007-10-18 12:05:00.000000000 +0200
@@ -360,10 +360,18 @@ void TIFFReader::ReadTagData( USHORT nTa
 			if ( ( nDataLen > nOldNumSO ) && ( nDataLen < SAL_MAX_UINT32 / sizeof( sal_uInt32 ) ) )
 			{
 				nNumStripOffsets = nDataLen;
-				pStripOffsets = new ULONG[ nNumStripOffsets ];
-				if ( !pStripOffsets )
+				try
+				{
+					pStripOffsets = new ULONG[ nNumStripOffsets ];
+					if ( pStripOffsets == NULL )
+						throw std::bad_alloc();
+				}
+	    			catch (std::bad_alloc)
+				{
+					pStripOffsets = NULL;
 					nNumStripOffsets = 0;
-				else
+				}
+				if ( pStripOffsets )
 				{
 					for ( i = 0; i < nOldNumSO; i++ )
 						pStripOffsets[ i ] = pOldSO[ i ] + nOrigPos;
@@ -400,10 +406,18 @@ void TIFFReader::ReadTagData( USHORT nTa
 			if ( ( nDataLen > nOldNumSBC ) && ( nDataLen < SAL_MAX_UINT32 / sizeof( sal_uInt32 ) ) )
 			{		
 				nNumStripByteCounts = nDataLen;
-				pStripByteCounts = new ULONG[ nNumStripByteCounts ];
-				if ( !nNumStripByteCounts )
+				try
+				{
+					pStripByteCounts = new ULONG[ nNumStripByteCounts ];
+					if ( pStripByteCounts == NULL )
+						throw std::bad_alloc();
+				}
+	    			catch (std::bad_alloc)
+				{
+					pStripByteCounts = NULL;
 					nNumStripByteCounts = 0;
-				else
+				}
+				if ( pStripByteCounts )
 				{
 					for ( i = 0; i < nOldNumSBC; i++ )
 						pStripByteCounts[ i ] = pOldSBC[ i ];
@@ -1240,9 +1252,22 @@ BOOL TIFFReader::ReadTIFF(SvStream & rTI
 					nBytesPerRow = ( nImageWidth * nSamplesPerPixel / nPlanes * nBitsPerSample + 7 ) >> 3;
 
 					for ( ULONG j = 0; j < 4; j++ )
-						pMap[ j ] = new BYTE[ nBytesPerRow ];
+					{
+						try
+						{
+							pMap[ j ] = new BYTE[ nBytesPerRow ];
+							if ( pMap[ j ] == NULL )
+								throw std::bad_alloc();
+						}
+	    					catch (std::bad_alloc)
+						{
+							pMap[ j ] = NULL;
+							bStatus = FALSE;
+							break;
+						}
+					}
 
-					if ( ReadMap( 10, 60 ) )
+					if ( bStatus && ReadMap( 10, 60 ) )
 					{
 						nMaxPos = Max( pTIFF->Tell(), nMaxPos );
 						MakePalCol();
--- goodies/source/filter.vcl/itiff/makefile.mk.old	2007-03-26 16:59:53.000000000 +0200
+++ goodies/source/filter.vcl/itiff/makefile.mk	2007-10-18 11:03:55.000000000 +0200
@@ -53,6 +53,8 @@ SLOFILES =  $(SLO)$/itiff.obj    \
 			$(SLO)$/lzwdecom.obj \
 			$(SLO)$/ccidecom.obj
 
+EXCEPTIONSNOOPTFILES=	$(SLO)$/itiff.obj
+
 # ==========================================================================
 
 SHL1TARGET=     iti$(UPD)$(DLLPOSTFIX)
--- svtools/source/filter.vcl/filter/filter.cxx.old	2007-08-02 20:18:50.000000000 +0200
+++ svtools/source/filter.vcl/filter/filter.cxx	2007-10-18 12:10:09.000000000 +0200
@@ -1648,6 +1648,35 @@ USHORT GraphicFilter::ImportGraphic( Gra
 			}
 		}
 	}
+
+	if( nStatus == GRFILTER_OK && bCreateNativeLink && ( eLinkType != GFX_LINK_TYPE_NONE ) && !rGraphic.GetContext() && !bLinkSet )
+	{
+		const ULONG nStmEnd = rIStream.Tell();
+		const ULONG	nBufSize = nStmEnd - nStmBegin;
+
+		if( nBufSize )
+		{
+			BYTE*	pBuf;
+			try
+			{
+				pBuf = new BYTE[ nBufSize ];
+				if ( pBuf == NULL )
+					throw std::bad_alloc();
+			}
+	    		catch (std::bad_alloc)
+			{
+				nStatus = GRFILTER_TOOBIG;
+			}
+
+			if( nStatus == GRFILTER_OK )
+			{
+				rIStream.Seek( nStmBegin );
+				rIStream.Read( pBuf, nBufSize );
+				rGraphic.SetLink( GfxLink( pBuf, nBufSize, eLinkType, TRUE ) );
+			}
+		}
+	}
+
 	// Set error code or try to set native buffer
 	if( nStatus != GRFILTER_OK )
 	{
@@ -1658,21 +1685,7 @@ USHORT GraphicFilter::ImportGraphic( Gra
 		rIStream.Seek( nStmBegin );
 		rGraphic.Clear();
 	}
-	else if( bCreateNativeLink && ( eLinkType != GFX_LINK_TYPE_NONE ) && !rGraphic.GetContext() && !bLinkSet )
-	{
-		const ULONG nStmEnd = rIStream.Tell();
-		const ULONG	nBufSize = nStmEnd - nStmBegin;
-
-		if( nBufSize )
-		{
-			BYTE*			pBuf = new BYTE[ nBufSize ];
-			//GraphicReader*	pOldContext = rGraphic.GetContext();
 
-			rIStream.Seek( nStmBegin );
-			rIStream.Read( pBuf, nBufSize );
-			rGraphic.SetLink( GfxLink( pBuf, nBufSize, eLinkType, TRUE ) );
-		}
-	}
     delete pFilterConfigItem;
 	return nStatus;
 }
