--- libwpd/libwpd-0.8.8.diff	23 Jan 2007 12:10:19 -0000	1.2
+++ libwpd/libwpd-0.8.8.diff	6 Feb 2007 12:49:46 -0000	1.2.4.1
@@ -1,5 +1,38 @@
-*** misc/libwpd-0.8.8/src/lib/WP1Part.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP1Part.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP1Heuristics.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1Heuristics.cpp	Tue Apr 17 16:20:47 2007
+***************
+*** 27,32 ****
+--- 27,33 ----
+  #include "WP1Heuristics.h"
+  #include "WP1FileStructure.h"
+  #include "libwpd_internal.h"
++ #include <limits>
+  
+  WPDConfidence WP1Heuristics::isWP1FileFormat(WPXInputStream *input, bool partialContent)
+  {
+***************
+*** 74,81 ****
+  				//   <function code>{function length}...{function length}<function code>
+  				//   that we observed in variable length WP1 functions 
+  				
+! 				long functionLength = readU32(input, true);
+! 				long closingFunctionLength = 0;
+  				WPD_DEBUG_MSG(("WP1Heuristics functionLength = 0x%.8x\n", (unsigned int)functionLength));
+  
+  				input->seek(functionLength, WPX_SEEK_CUR);
+--- 75,84 ----
+  				//   <function code>{function length}...{function length}<function code>
+  				//   that we observed in variable length WP1 functions 
+  				
+! 				unsigned long functionLength = readU32(input, true);
+! 				if (functionLength > ((std::numeric_limits<uint32_t>::max)() / 2))
+! 					return WPD_CONFIDENCE_NONE;
+! 				unsigned long closingFunctionLength = 0;
+  				WPD_DEBUG_MSG(("WP1Heuristics functionLength = 0x%.8x\n", (unsigned int)functionLength));
+  
+  				input->seek(functionLength, WPX_SEEK_CUR);
+*** misc/libwpd-0.8.8/src/lib/WP1Part.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1Part.cpp	Tue Apr 17 16:09:57 2007
 ***************
 *** 46,51 ****
 --- 46,58 ----
@@ -16,8 +49,8 @@
   		WPD_DEBUG_MSG(("WordPerfect: constructVariableLengthGroup\n"));
   		return WP1VariableLengthGroup::constructVariableLengthGroup(input, readVal);
   	}
-*** misc/libwpd-0.8.8/src/lib/WP1SetTabsGroup.cpp	2007-01-05 11:21:16.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP1SetTabsGroup.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP1SetTabsGroup.cpp	Fri Jan  5 11:21:16 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1SetTabsGroup.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 39,45 ****
   void WP1SetTabsGroup::_readContents(WPXInputStream *input)
@@ -56,8 +89,8 @@
   		tmpTabPosition = (float)((double)readU16(input, true) / 72.0f);
   
   		if (tmpTabType < 0)
-*** misc/libwpd-0.8.8/src/lib/WP1SubDocument.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP1SubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP1SubDocument.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1SubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,32 ****
   #include "WP1Parser.h"
@@ -75,8 +108,8 @@
   	WPXSubDocument(input, dataSize)
   {
   }
-*** misc/libwpd-0.8.8/src/lib/WP1SubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP1SubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP1SubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1SubDocument.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,38 ****
   class WP1SubDocument : public WPXSubDocument
@@ -94,8 +127,64 @@
   	void parse(WP1Listener *listener) const;
   
   };
-*** misc/libwpd-0.8.8/src/lib/WP3PageFormatGroup.cpp	2007-01-05 11:21:13.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP3PageFormatGroup.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP1VariableLengthGroup.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP1VariableLengthGroup.cpp	Tue Apr 17 16:34:55 2007
+***************
+*** 31,36 ****
+--- 31,37 ----
+  #include "WP1FootnoteEndnoteGroup.h"
+  #include "WP1FileStructure.h"
+  #include "libwpd_internal.h"
++ #include <limits>
+  
+  WP1VariableLengthGroup::WP1VariableLengthGroup(uint8_t group)
+  	: m_group(group)
+***************
+*** 60,65 ****
+--- 61,68 ----
+  	try
+  	{
+  		uint32_t size = readU32(input, true);
++ 		if (size > ((std::numeric_limits<uint32_t>::max)() / 2))
++ 			return false;
+  
+  		if (input->seek(size, WPX_SEEK_CUR) || input->atEOS())
+  		{
+***************
+*** 94,104 ****
+--- 97,114 ----
+  	WPD_DEBUG_MSG(("WordPerfect: handling a variable length group\n"));	
+  	
+  	m_size = readU32(input, true); // the length is the number of data bytes minus 4 (ie. the function codes)
++ 
++ 	if (m_size + startPosition < startPosition)
++ 		throw FileException(); 
+  	
+  	WPD_DEBUG_MSG(("WordPerfect: Read variable group header (start_position: %i, size: %i)\n", startPosition, m_size));
+  	
+  	_readContents(input);
+  	
++ 	if ((m_size + startPosition + 4 < m_size + startPosition) ||
++ 		(m_size + startPosition + 4) > ((std::numeric_limits<uint32_t>::max)() / 2))
++ 		throw FileException(); 
++ 	
+  	input->seek(startPosition + m_size + 4, WPX_SEEK_SET);
+  
+  	if (m_size != readU32(input, true))
+***************
+*** 112,117 ****
+--- 122,130 ----
+  		throw FileException();
+  	}
+  	
++ 	if ((m_size + startPosition + 9 < m_size + startPosition) ||
++ 		(m_size + startPosition + 9) > ((std::numeric_limits<uint32_t>::max)() / 2))
++ 		throw FileException(); 
+  	input->seek(startPosition + m_size + 9, WPX_SEEK_SET);
+  
+  }
+*** misc/libwpd-0.8.8/src/lib/WP3PageFormatGroup.cpp	Fri Jan  5 11:21:13 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP3PageFormatGroup.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 91,98 ****
   
@@ -117,8 +206,8 @@
   			tmpTabPosition = fixedPointToFloat(readU32(input, true)) / 72.0f;
   
   			if (tmpTabType < 0)
-*** misc/libwpd-0.8.8/src/lib/WP3SubDocument.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP3SubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP3SubDocument.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP3SubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,32 ****
   #include "WP3Parser.h"
@@ -136,8 +225,8 @@
   	WPXSubDocument(input, dataSize)
   {
   }
-*** misc/libwpd-0.8.8/src/lib/WP3SubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP3SubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP3SubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP3SubDocument.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,38 ****
   class WP3SubDocument : public WPXSubDocument
@@ -155,8 +244,8 @@
   	void parse(WP3Listener *listener) const;
   
   };
-*** misc/libwpd-0.8.8/src/lib/WP3TablesGroup.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP3TablesGroup.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP3TablesGroup.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP3TablesGroup.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 50,59 ****
   {
@@ -214,8 +303,41 @@
   			listener->addTableColumnDefinition(fixedPointToWPUs(m_columnWidth[i]), fixedPointToWPUs(m_leftGutterSpacing),
   								fixedPointToWPUs(m_rightGutterSpacing), 0, LEFT);
   		listener->startTable();
-*** misc/libwpd-0.8.8/src/lib/WP42SubDocument.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP42SubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP3VariableLengthGroup.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP3VariableLengthGroup.cpp	Tue Apr 17 16:37:17 2007
+***************
+*** 36,41 ****
+--- 36,42 ----
+  #include "WP3FootnoteEndnoteGroup.h"
+  #include "WP3TablesGroup.h"
+  #include "libwpd_internal.h"
++ #include <limits>
+  
+  WP3VariableLengthGroup::WP3VariableLengthGroup()
+  {
+***************
+*** 72,82 ****
+--- 73,90 ----
+  bool WP3VariableLengthGroup::isGroupConsistent(WPXInputStream *input, const uint8_t group)
+  {
+  	uint32_t startPosition = input->tell();
++ 	if (startPosition > ((std::numeric_limits<unsigned long>::max)() / 2))
++ 		return false;
+  
+  	try
+  	{
+  		uint8_t subGroup = readU8(input);
+  		uint16_t size = readU16(input, true);
++ 		if (startPosition + size < startPosition)
++ 		{
++ 			input->seek(startPosition, WPX_SEEK_SET);
++ 			return false;
++ 		}
+  
+  		if (input->seek((startPosition + size - 1 - input->tell()), WPX_SEEK_CUR) || input->atEOS())
+  		{
+*** misc/libwpd-0.8.8/src/lib/WP42SubDocument.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP42SubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,37 ****
   #include "WP42Parser.h"
@@ -243,8 +365,8 @@
   	WPXSubDocument(input, dataSize)
   {
   }
-*** misc/libwpd-0.8.8/src/lib/WP42SubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP42SubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP42SubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP42SubDocument.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,39 ****
   class WP42SubDocument : public WPXSubDocument
@@ -264,8 +386,8 @@
   	void parse(WP42Listener *listener) const;
   
   };
-*** misc/libwpd-0.8.8/src/lib/WP5DefinitionGroup.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP5DefinitionGroup.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP5DefinitionGroup.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP5DefinitionGroup.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,32 ****
   #include "WP5Listener.h"
@@ -339,8 +461,8 @@
   			break;
   		default:
   			break;
-*** misc/libwpd-0.8.8/src/lib/WP5DefinitionGroup.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP5DefinitionGroup.h	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP5DefinitionGroup.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP5DefinitionGroup.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 31,37 ****
   class WP5DefinitionGroup_DefineTablesSubGroup : public WP5VariableLengthGroup_SubGroup
@@ -368,8 +490,8 @@
   
   #endif /* WP5DEFINITIONGROUP_H */
 --- 58,63 ----
-*** misc/libwpd-0.8.8/src/lib/WP5SubDocument.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP5SubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP5SubDocument.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP5SubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,32 ****
   #include "WP5Parser.h"
@@ -387,8 +509,8 @@
   	WPXSubDocument(input, dataSize)
   {
   }
-*** misc/libwpd-0.8.8/src/lib/WP5SubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP5SubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP5SubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP5SubDocument.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,38 ****
   class WP5SubDocument : public WPXSubDocument
@@ -406,8 +528,8 @@
   	void parse(WP5Listener *listener) const;
   
   };
-*** misc/libwpd-0.8.8/src/lib/WP6ExtendedDocumentSummaryPacket.cpp	2007-01-05 11:30:07.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6ExtendedDocumentSummaryPacket.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6ExtendedDocumentSummaryPacket.cpp	Fri Jan  5 11:30:07 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6ExtendedDocumentSummaryPacket.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 24,29 ****
 --- 24,30 ----
@@ -429,8 +551,8 @@
   	uint8_t *streamData = new uint8_t[m_dataSize];
   	for(unsigned i=0; i<(unsigned)m_dataSize; i++)
   		streamData[i] = readU8(input);
-*** misc/libwpd-0.8.8/src/lib/WP6FontDescriptorPacket.cpp	2007-01-04 12:52:35.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6FontDescriptorPacket.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6FontDescriptorPacket.cpp	Thu Jan  4 12:52:35 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6FontDescriptorPacket.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 23,29 ****
    * Corel Corporation or Corel Corporation Limited."
@@ -469,8 +591,8 @@
      if (m_fontNameLength == 0) 
   	   {
   		   m_fontName = new char[1];
-*** misc/libwpd-0.8.8/src/lib/WP6GeneralTextPacket.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6GeneralTextPacket.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6GeneralTextPacket.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6GeneralTextPacket.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 43,48 ****
 --- 43,49 ----
@@ -526,8 +648,8 @@
   		for (unsigned int j=0; j<blockSizes[i]; j++)
   		{
   			streamData[streamPos] = readU8(input);
-*** misc/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.cpp	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 35,41 ****
   #include "libwpd.h"
@@ -565,8 +687,8 @@
   		return;
   
   	input->seek(dataOffset, WPX_SEEK_SET);
-*** misc/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.h	2007-01-13 00:18:52.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6PrefixDataPacket.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 39,50 ****
 --- 39,54 ----
@@ -586,8 +708,8 @@
   };
   
   #endif /* WP6PREFIXDATAPACKET_H */
-*** misc/libwpd-0.8.8/src/lib/WP6SubDocument.cpp	2007-01-03 14:07:55.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6SubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6SubDocument.cpp	Wed Jan  3 14:07:55 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6SubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 26,32 ****
   #include "WP6Parser.h"
@@ -605,8 +727,8 @@
   	WPXSubDocument(streamData, dataSize)
   {
   }
-*** misc/libwpd-0.8.8/src/lib/WP6SubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WP6SubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WP6SubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WP6SubDocument.h	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,38 ****
   class WP6SubDocument : public WPXSubDocument
@@ -624,8 +746,8 @@
   	void parse(WP6Listener *listener) const;
   };
   #endif /* WP6SUBDOCUMENT_H */
-*** misc/libwpd-0.8.8/src/lib/WPXSubDocument.cpp	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WPXSubDocument.cpp	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WPXSubDocument.cpp	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WPXSubDocument.cpp	Tue Apr 17 16:09:58 2007
 ***************
 *** 32,49 ****
   {
@@ -667,8 +789,8 @@
   	m_stream(0)
   {
   	m_stream = new WPXMemoryInputStream(streamData, dataSize);
-*** misc/libwpd-0.8.8/src/lib/WPXSubDocument.h	2007-01-03 14:07:56.000000000 +0100
---- misc/build/libwpd-0.8.8/src/lib/WPXSubDocument.h	2007-01-15 11:03:37.000000000 +0100
+*** misc/libwpd-0.8.8/src/lib/WPXSubDocument.h	Wed Jan  3 14:07:56 2007
+--- misc/build/libwpd-0.8.8/src/lib/WPXSubDocument.h	Tue Apr 17 16:09:59 2007
 ***************
 *** 33,40 ****
   {
@@ -688,3 +810,17 @@
   	virtual ~WPXSubDocument();
   	WPXMemoryInputStream *getStream() const { return m_stream;}
   
+*** misc/libwpd-0.8.8/src/lib/makefile.mk	Tue Nov 14 15:45:50 2006
+--- misc/build/libwpd-0.8.8/src/lib/makefile.mk	Tue Apr 17 16:09:59 2007
+***************
+*** 7,15 ****
+  ENABLE_EXCEPTIONS=TRUE
+  LIBTARGET=NO
+  
+- .INCLUDE :  svpre.mk
+  .INCLUDE :  settings.mk
+- .INCLUDE :  sv.mk
+  
+  .IF "$(GUI)"=="WNT"
+  CFLAGS+=-GR
+--- 7,13 ----
--- writerperfect/source/stream/WPXSvStream.cxx	23 Jan 2007 12:18:14 -0000	1.6
+++ writerperfect/source/stream/WPXSvStream.cxx	6 Feb 2007 12:49:23 -0000	1.6.2.1
@@ -3,6 +3,7 @@
 #include <tools/stream.hxx>
 #include <unotools/streamwrap.hxx>
 #include <unotools/ucbstreamhelper.hxx>
+#include <limits>
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::io;
@@ -59,7 +60,12 @@ long WPXSvInputStream::tell()
 	if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
 		return -1L;
 	else
-		return (long)mxSeekable->getPosition();
+	{
+		sal_Int64 tmpPosition = mxSeekable->getPosition();
+		if ((tmpPosition < 0) || (tmpPosition > (std::numeric_limits<long>::max)()))
+			return -1L;
+		return (long)tmpPosition;
+	}
 }
 
 int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType) 
@@ -68,24 +74,28 @@ int WPXSvInputStream::seek(long offset, 
 		return -1;
 
 	sal_Int64 tmpPosition = mxSeekable->getPosition();
+	if ((tmpPosition < 0) || (tmpPosition > (std::numeric_limits<long>::max)()))
+		return -1;
+
+	sal_Int64 tmpOffset = offset;
 	if (seekType == WPX_SEEK_CUR)
-		offset += tmpPosition;
+		tmpOffset += sal::static_int_cast<long, sal_Int64>(tmpPosition);
 
 	int retVal = 0;
-	if (offset < 0)
+	if (tmpOffset < 0)
 	{	
-		offset = 0;
+		tmpOffset = 0;
 		retVal = -1;
 	}
 	if (offset > mnLength)
 	{
-		offset = mnLength;
+		tmpOffset = sal::static_int_cast<long, sal_Int64>(mnLength);
 		retVal = -1;
 	}
 
 	try
 	{
-		mxSeekable->seek(offset);
+		mxSeekable->seek(tmpOffset);
 		return retVal;
 	}
 	catch (...)
