[Box Backup-commit] COMMIT r2792 - in box/invisnet/vs2010/0.11/lib: backupclient common compress crypto server

subversion at boxbackup.org subversion at boxbackup.org
Sun Oct 17 22:31:29 BST 2010


Author: invisnet
Date: 2010-10-17 22:31:28 +0100 (Sun, 17 Oct 2010)
New Revision: 2792

Modified:
   box/invisnet/vs2010/0.11/lib/backupclient/BackupClientFileAttributes.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupClientRestore.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.h
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.h
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbDiff.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbIdx.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCombine.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileDiff.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.h
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileRevDiff.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilename.h
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.cpp
   box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.h
   box/invisnet/vs2010/0.11/lib/common/Archive.h
   box/invisnet/vs2010/0.11/lib/common/BufferedStream.cpp
   box/invisnet/vs2010/0.11/lib/common/BufferedStream.h
   box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.cpp
   box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.h
   box/invisnet/vs2010/0.11/lib/common/ExcludeList.cpp
   box/invisnet/vs2010/0.11/lib/common/ExcludeList.h
   box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp
   box/invisnet/vs2010/0.11/lib/common/FileStream.cpp
   box/invisnet/vs2010/0.11/lib/common/FileStream.h
   box/invisnet/vs2010/0.11/lib/common/Guards.h
   box/invisnet/vs2010/0.11/lib/common/IOStream.cpp
   box/invisnet/vs2010/0.11/lib/common/IOStream.h
   box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.cpp
   box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.h
   box/invisnet/vs2010/0.11/lib/common/MemBlockStream.cpp
   box/invisnet/vs2010/0.11/lib/common/MemBlockStream.h
   box/invisnet/vs2010/0.11/lib/common/PartialReadStream.cpp
   box/invisnet/vs2010/0.11/lib/common/PartialReadStream.h
   box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.cpp
   box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.h
   box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.cpp
   box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.h
   box/invisnet/vs2010/0.11/lib/common/SelfFlushingStream.h
   box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.cpp
   box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.h
   box/invisnet/vs2010/0.11/lib/common/Utils.cpp
   box/invisnet/vs2010/0.11/lib/common/ZeroStream.cpp
   box/invisnet/vs2010/0.11/lib/common/ZeroStream.h
   box/invisnet/vs2010/0.11/lib/compress/Compress.h
   box/invisnet/vs2010/0.11/lib/compress/CompressStream.cpp
   box/invisnet/vs2010/0.11/lib/compress/CompressStream.h
   box/invisnet/vs2010/0.11/lib/crypto/CipherContext.cpp
   box/invisnet/vs2010/0.11/lib/crypto/CipherContext.h
   box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.cpp
   box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.h
   box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.cpp
   box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.h
   box/invisnet/vs2010/0.11/lib/server/Protocol.cpp
   box/invisnet/vs2010/0.11/lib/server/Protocol.h
   box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.cpp
   box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.h
   box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.cpp
   box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.h
   box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.cpp
   box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.h
   box/invisnet/vs2010/0.11/lib/server/makeprotocol.pl.in
Log:
Under Windows sizeof(int)==4 on both x86 and x64, so switch from int to size_t with checks for overflow.
Add some overflow checks before calling malloc().

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupClientFileAttributes.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupClientFileAttributes.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupClientFileAttributes.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -301,11 +301,11 @@
 	}
 	
 	// Check symlink string?
-	unsigned int size = mpClearAttributes->GetSize();
+	size_t size = mpClearAttributes->GetSize();
 	if(size > sizeof(attr_StreamFormat))
 	{
 		// Symlink strings don't match. This also compares xattrs
-		int datalen = size - sizeof(attr_StreamFormat);
+		size_t datalen = size - sizeof(attr_StreamFormat);
 
 		if(::memcmp(a1 + 1, a2 + 1, datalen) != 0)
 		{
@@ -726,7 +726,7 @@
 	ASSERT(mpClearAttributes != 0);
 
 	// Check if the decrypted attributes are small enough, and the type of attributes stored
-	if(mpClearAttributes->GetSize() < (int)sizeof(int32_t))
+	if(mpClearAttributes->GetSize() < sizeof(int32_t))
 	{
 		THROW_EXCEPTION(BackupStoreException, AttributesNotUnderstood);
 	}
@@ -739,7 +739,7 @@
 	}
 	
 	// Check there is enough space for an attributes block
-	if(mpClearAttributes->GetSize() < (int)sizeof(attr_StreamFormat))
+	if(mpClearAttributes->GetSize() < sizeof(attr_StreamFormat))
 	{
 		// Too small
 		THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded);
@@ -747,14 +747,14 @@
 
 	// Get pointer to structure
 	attr_StreamFormat *pattr = (attr_StreamFormat*)mpClearAttributes->GetBuffer();
-	int xattrOffset = sizeof(attr_StreamFormat);
+	size_t xattrOffset = sizeof(attr_StreamFormat);
 
 	// is it a symlink?
 	int16_t mode = ntohs(pattr->Mode);
 	if((mode & S_IFMT) == S_IFLNK)
 	{
 		// Check things are sensible
-		if(mpClearAttributes->GetSize() < (int)sizeof(attr_StreamFormat) + 1)
+		if(mpClearAttributes->GetSize() < sizeof(attr_StreamFormat) + 1)
 		{
 			// Too small
 			THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded);
@@ -804,10 +804,12 @@
 		#endif
 	}
 
-	if(static_cast<int>(xattrOffset+sizeof(u_int32_t))<=mpClearAttributes->GetSize())
-	{
-		WriteExtendedAttr(Filename, xattrOffset);
-	}
+	#ifdef HAVE_SYS_XATTR_H
+		if(static_cast<int>(xattrOffset+sizeof(u_int32_t))<=mpClearAttributes->GetSize())
+		{
+			WriteExtendedAttr(Filename, xattrOffset);
+		}
+	#endif
 
 	// Stop now if symlink, because otherwise it'll just be applied to the target
 	if((mode & S_IFMT) == S_IFLNK)
@@ -1004,14 +1006,14 @@
 	try
 	{
 		// Check the block is big enough for IV and header
-		int ivSize = sBlowfishEncrypt.GetIVLength();
+		size_t ivSize = sBlowfishEncrypt.GetIVLength();
 		if(rEncrypted.GetSize() <= (ivSize + 1))
 		{
 			THROW_EXCEPTION(BackupStoreException, BadEncryptedAttributes);
 		}
 		
 		// How much space is needed for the output?
-		int maxDecryptedSize = sBlowfishDecrypt.MaxOutSizeForInBufferSize(rEncrypted.GetSize() - ivSize);
+		size_t maxDecryptedSize = sBlowfishDecrypt.MaxOutSizeForInBufferSize(rEncrypted.GetSize() - ivSize);
 		
 		// Allocate it
 		pdecrypted = new StreamableMemBlock(maxDecryptedSize);
@@ -1029,7 +1031,7 @@
 		sBlowfishDecrypt.SetIV(encBlock + 1);
 		
 		// Decrypt
-		int decryptedSize = sBlowfishDecrypt.TransformBlock(pdecrypted->GetBuffer(), maxDecryptedSize, encBlock + 1 + ivSize, rEncrypted.GetSize() - (ivSize + 1));
+		size_t decryptedSize = sBlowfishDecrypt.TransformBlock(pdecrypted->GetBuffer(), maxDecryptedSize, encBlock + 1 + ivSize, rEncrypted.GetSize() - (ivSize + 1));
 
 		// Resize block to fit
 		pdecrypted->ResizeBlock(decryptedSize);
@@ -1077,7 +1079,7 @@
 	FreeBlock();
 	
 	// Work out the maximum amount of space we need
-	int maxEncryptedSize = sBlowfishEncrypt.MaxOutSizeForInBufferSize(rToEncrypt.GetSize());
+	size_t maxEncryptedSize = sBlowfishEncrypt.MaxOutSizeForInBufferSize(rToEncrypt.GetSize());
 	// And the size of the IV
 	int ivSize = sBlowfishEncrypt.GetIVLength();
 	
@@ -1097,7 +1099,7 @@
 	::memcpy(block + 1, iv, ivSize);
 	
 	// Do the transform
-	int encrytedSize = sBlowfishEncrypt.TransformBlock(block + 1 + ivSize, maxEncryptedSize, rToEncrypt.GetBuffer(), rToEncrypt.GetSize());
+	size_t encrytedSize = sBlowfishEncrypt.TransformBlock(block + 1 + ivSize, maxEncryptedSize, rToEncrypt.GetBuffer(), rToEncrypt.GetSize());
 
 	// Resize this block
 	ResizeBlock(encrytedSize + ivSize + 1);

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupClientRestore.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupClientRestore.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -105,7 +105,7 @@
 			// ID
 			rWrite.Write(&mNextLevelID, sizeof(mNextLevelID));
 			// Name string
-			int32_t nsize = mNextLevelLocalName.size();
+			size_t nsize = mNextLevelLocalName.size();
 			rWrite.Write(&nsize, sizeof(nsize));
 			rWrite.Write(mNextLevelLocalName.c_str(), nsize);
 			// And then the level itself
@@ -440,8 +440,8 @@
 	// list of files which is appropriate to the restore type
 	rConnection.QueryListDirectory(
 		DirectoryID,
-		Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING),
-		BackupProtocolClientListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolClientListDirectory::Flags_Deleted)),
+		static_cast<int16_t>(Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING)),
+		static_cast<int16_t>(BackupProtocolClientListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolClientListDirectory::Flags_Deleted))),
 		true /* want attributes */);
 
 	// Retrieve the directory from the stream following

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -146,7 +146,7 @@
 	mAttributes.ReadFromStream(rStream, Timeout);
 	
 	// Decode count
-	int count = ntohl(hdr.mNumEntries);
+	int32_t count = ntohl(hdr.mNumEntries);
 	
 	// Clear existing list
 	for(std::vector<Entry*>::iterator i = mEntries.begin(); 
@@ -157,7 +157,7 @@
 	mEntries.clear();
 	
 	// Read them in!
-	for(int c = 0; c < count; ++c)
+	for(int32_t c = 0; c < count; ++c)
 	{
 		Entry *pen = new Entry;
 		try
@@ -179,7 +179,7 @@
 	if(options & Option_DependencyInfoPresent)
 	{
 		// Read in extra dependency data
-		for(int c = 0; c < count; ++c)
+		for(int32_t c = 0; c < count; ++c)
 		{
 			mEntries[c]->ReadFromStreamDependencyInfo(rStream, Timeout);
 		}
@@ -197,7 +197,8 @@
 void BackupStoreDirectory::WriteToStream(IOStream &rStream, int16_t FlagsMustBeSet, int16_t FlagsNotToBeSet, bool StreamAttributes, bool StreamDependencyInfo) const
 {
 	// Get count of entries
-	int32_t count = mEntries.size();
+	size_t count = mEntries.size();
+	ASSERT(count < (size_t)std::numeric_limits<int32_t>::max());
 	if(FlagsMustBeSet != Entry::Flags_INCLUDE_EVERYTHING || FlagsNotToBeSet != Entry::Flags_EXCLUDE_NOTHING)
 	{
 		// Need to count the entries
@@ -235,7 +236,7 @@
 	// Build header
 	dir_StreamFormat hdr;
 	hdr.mMagicValue = htonl(OBJECTMAGIC_DIR_MAGIC_VALUE);
-	hdr.mNumEntries = htonl(count);
+	hdr.mNumEntries = htonl(static_cast<int32_t>(count));
 	hdr.mObjectID = box_hton64(mObjectID);
 	hdr.mContainerID = box_hton64(mContainerID);
 	hdr.mAttributesModTime = box_hton64(mAttributesModTime);

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreDirectory.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -146,7 +146,7 @@
 	int64_t GetRevisionID() const {return mRevisionID;}
 	void SetRevisionID(int64_t RevisionID) {mRevisionID = RevisionID;}
 	
-	unsigned int GetNumberOfEntries() const {return mEntries.size();}
+	size_t GetNumberOfEntries() const {return mEntries.size();}
 
 	// User info -- not serialised into streams
 	int64_t GetUserInfo1_SizeInBlocks() const {return mUserInfo1;}

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -542,7 +542,7 @@
 	if(mNumBlocks > 0)
 	{
 		// Find the maximum encoded data size
-		int32_t maxEncodedDataSize = 0;
+		int64_t maxEncodedDataSize = 0;
 		const file_BlockIndexEntry *entry = (file_BlockIndexEntry *)mpBlockIndex;
 		ASSERT(entry != 0);
 		for(int64_t e = 0; e < mNumBlocks; e++)
@@ -554,9 +554,10 @@
 			// Larger?
 			if(encodedSize > maxEncodedDataSize) maxEncodedDataSize = encodedSize;
 		}
-		
+
 		// Allocate those blocks!
-		mpEncodedData = (uint8_t*)BackupStoreFile::CodingChunkAlloc(maxEncodedDataSize + 32);
+		ASSERT(maxEncodedDataSize+32 < SIZE_MAX);
+		mpEncodedData = (uint8_t*)BackupStoreFile::CodingChunkAlloc(static_cast<size_t>(maxEncodedDataSize + 32));
 
 		// Allocate the block for the clear data, using the hint from the header.
 		// If this is wrong, things will exception neatly later on, so it can't be used
@@ -624,7 +625,11 @@
 		int64_t indexSize = sizeof(file_BlockIndexEntry) * mNumBlocks;
 		
 		// Allocate some memory
-		mpBlockIndex = ::malloc(indexSize);
+		if(indexSize >= SIZE_MAX)
+		{
+			throw std::bad_alloc();
+		}
+		mpBlockIndex = ::malloc(static_cast<size_t>(indexSize));
 		if(mpBlockIndex == 0)
 		{
 			throw std::bad_alloc();
@@ -648,7 +653,7 @@
 //		Created: 9/12/03
 //
 // --------------------------------------------------------------------------
-int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t BackupStoreFile::DecodedStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Symlinks don't have data. So can't read it. Not even zero bytes.
 	if(IsSymLink())
@@ -664,7 +669,7 @@
 		return 0;
 	}
 
-	int bytesToRead = NBytes;
+	size_t bytesToRead = NBytes;
 	uint8_t *output = (uint8_t*)pBuffer;
 	
 	while(bytesToRead > 0 && mCurrentBlock < mNumBlocks)
@@ -673,7 +678,7 @@
 		if(mPositionInCurrentBlock < mCurrentBlockClearSize)
 		{
 			// Copy data out of this buffer
-			int s = mCurrentBlockClearSize - mPositionInCurrentBlock;
+			size_t s = mCurrentBlockClearSize - mPositionInCurrentBlock;
 			if(s > bytesToRead) s = bytesToRead;	// limit to requested data
 			
 			// Copy
@@ -698,7 +703,7 @@
 		
 			// Get the size from the block index
 			const file_BlockIndexEntry *entry = (file_BlockIndexEntry *)mpBlockIndex;
-			int32_t encodedSize = box_ntoh64(entry[mCurrentBlock].mEncodedSize);
+			int64_t encodedSize = box_ntoh64(entry[mCurrentBlock].mEncodedSize);
 			if(encodedSize <= 0)
 			{
 				// The caller is attempting to decode a file which is the direct result of a diff
@@ -706,6 +711,11 @@
 				// It needs to be combined with the previous version first.
 				THROW_EXCEPTION(BackupStoreException, CannotDecodeDiffedFilesWithoutCombining)
 			}
+			if(encodedSize >= SIZE_MAX)
+			{
+				// We're on a 32bit machine and this block is too big for us to deal with
+				THROW_EXCEPTION(BackupStoreException, Internal)
+			}
 			
 			// Load in next block
 			if(!mrEncodedFile.ReadFullBuffer(mpEncodedData, encodedSize, 0 /* not interested in bytes read if this fails */, mTimeout))
@@ -715,7 +725,7 @@
 			}
 			
 			// Decode the data
-			mCurrentBlockClearSize = BackupStoreFile::DecodeChunk(mpEncodedData, encodedSize, mpClearData, mClearDataSize);
+			mCurrentBlockClearSize = BackupStoreFile::DecodeChunk(mpEncodedData, static_cast<size_t>(encodedSize), mpClearData, mClearDataSize);
 
 			// Calculate IV for this entry
 			uint64_t iv = mEntryIVBase;
@@ -727,7 +737,7 @@
 			
 			// Decrypt the encrypted section
 			file_BlockIndexEntryEnc entryEnc;
-			int sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
+			size_t sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
 					entry[mCurrentBlock].mEnEnc, sizeof(entry[mCurrentBlock].mEnEnc));
 			if(sectionSize != sizeof(entryEnc))
 			{
@@ -746,7 +756,7 @@
 				// IV for the encrypted section. Try again, with the thing the other way round
 				iv = box_swap64(iv);
 				sBlowfishDecryptBlockEntry.SetIV(&iv);
-				int sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
+				size_t sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
 						entry[mCurrentBlock].mEnEnc, sizeof(entry[mCurrentBlock].mEnEnc));
 				if(sectionSize != sizeof(entryEnc))
 				{
@@ -826,7 +836,7 @@
 //		Created: 9/12/03
 //
 // --------------------------------------------------------------------------
-void BackupStoreFile::DecodedStream::Write(const void *pBuffer, int NBytes)
+void BackupStoreFile::DecodedStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(BackupStoreException, CantWriteToDecodedFileStream)
 }
@@ -922,7 +932,7 @@
 //		Created: 7/12/03
 //
 // --------------------------------------------------------------------------
-int BackupStoreFile::MaxBlockSizeForChunkSize(int ChunkSize)
+size_t BackupStoreFile::MaxBlockSizeForChunkSize(size_t ChunkSize)
 {
 	// Calculate... the maximum size of output by first the largest it could be after compression,
 	// which is encrypted, and has a 1 bytes header and the IV added, plus 1 byte for luck
@@ -942,7 +952,7 @@
 //		Created: 8/12/03
 //
 // --------------------------------------------------------------------------
-int BackupStoreFile::EncodeChunk(const void *Chunk, int ChunkSize, BackupStoreFile::EncodingBuffer &rOutput)
+size_t BackupStoreFile::EncodeChunk(const void *Chunk, size_t ChunkSize, BackupStoreFile::EncodingBuffer &rOutput)
 {
 	ASSERT(spEncrypt != 0);
 
@@ -964,7 +974,7 @@
 
 	// Store header
 	rOutput.mpBuffer[0] = header;
-	int outOffset = 1;
+	size_t outOffset = 1;
 
 	// Setup cipher, and store the IV
 	int ivLen = 0;
@@ -977,6 +987,7 @@
 	
 	#define ENCODECHUNK_CHECK_SPACE(ToEncryptSize)									\
 		{																			\
+			ASSERT(rOutput.mBufferSize >= outOffset);	\
 			if((rOutput.mBufferSize - outOffset) < ((ToEncryptSize) + 128))			\
 			{																		\
 				rOutput.Reallocate(rOutput.mBufferSize + (ToEncryptSize) + 128);	\
@@ -997,7 +1008,7 @@
 		// Get and encrypt output
 		while(!compress.OutputHasFinished())
 		{
-			int s = compress.Output(buffer, sizeof(buffer));
+			size_t s = compress.Output(buffer, sizeof(buffer));
 			if(s > 0)
 			{
 				ENCODECHUNK_CHECK_SPACE(s)
@@ -1038,7 +1049,7 @@
 //		Created: 8/12/03
 //
 // --------------------------------------------------------------------------
-int BackupStoreFile::DecodeChunk(const void *Encoded, int EncodedSize, void *Output, int OutputSize)
+size_t BackupStoreFile::DecodeChunk(const void *Encoded, size_t EncodedSize, void *Output, size_t OutputSize)
 {
 	// Check alignment of the encoded block
 	ASSERT((((uint32_t)(long)Encoded) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET);
@@ -1073,8 +1084,8 @@
 #endif
 	
 	// Check enough space for header, an IV and one byte of input
-	int ivLen = cipher.GetIVLength();
-	if(EncodedSize < (1 + ivLen + 1))
+	size_t ivLen = cipher.GetIVLength();
+	if(EncodedSize < 1 + ivLen + 1)
 	{
 		THROW_EXCEPTION(BackupStoreException, BadEncodedChunk)
 	}
@@ -1084,16 +1095,16 @@
 	cipher.Begin();
 	
 	// Setup vars for code
-	int inOffset = 1 + ivLen;
+	size_t inOffset = 1 + ivLen;
 	uint8_t *output = (uint8_t*)Output;
-	int outOffset = 0;
+	size_t outOffset = 0;
 
 	// Do action
 	if(chunkCompressed)
 	{
 		// Do things in chunks
 		uint8_t buffer[2048];
-		int inputBlockLen = cipher.InSizeForOutBufferSize(sizeof(buffer));
+		size_t inputBlockLen = cipher.InSizeForOutBufferSize(sizeof(buffer));
 		
 		// Decompressor
 		Compress<false> decompress;
@@ -1101,16 +1112,16 @@
 		while(inOffset < EncodedSize)
 		{
 			// Decrypt a block
-			int bl = inputBlockLen;
+			size_t bl = inputBlockLen;
 			if(bl > (EncodedSize - inOffset)) bl = EncodedSize - inOffset;	// not too long
-			int s = cipher.Transform(buffer, sizeof(buffer), input + inOffset, bl);
+			size_t s = cipher.Transform(buffer, sizeof(buffer), input + inOffset, bl);
 			inOffset += bl;
 			
 			// Decompress the decrypted data
 			if(s > 0)
 			{
 				decompress.Input(buffer, s);
-				int os = 0;
+				size_t os = 0;
 				do
 				{
 					os = decompress.Output(output + outOffset, OutputSize - outOffset);
@@ -1126,12 +1137,12 @@
 		}
 		
 		// Get any compressed data remaining in the cipher context and compression
-		int s = cipher.Final(buffer, sizeof(buffer));
+		size_t s = cipher.Final(buffer, sizeof(buffer));
 		decompress.Input(buffer, s);
 		decompress.FinishInput();
 		while(!decompress.OutputHasFinished())
 		{
-			int os = decompress.Output(output + outOffset, OutputSize - outOffset);
+			size_t os = decompress.Output(output + outOffset, OutputSize - outOffset);
 			outOffset += os;
 
 			// Check that there's space left in the output buffer -- there always should be
@@ -1143,6 +1154,9 @@
 	}
 	else
 	{
+		ASSERT(OutputSize >= outOffset);
+		ASSERT(EncodedSize >= inOffset);
+
 		// Easy decryption
 		outOffset += cipher.Transform(output + outOffset, OutputSize - outOffset, input + inOffset, EncodedSize - inOffset);
 		outOffset += cipher.Final(output + outOffset, OutputSize - outOffset);
@@ -1176,7 +1190,7 @@
 	}
 
 	// Read the header
-	int bytesRead = 0;
+	size_t bytesRead = 0;
 	file_StreamFormat hdr;
 	bool readBlock = pStream->ReadFullBuffer(&hdr, sizeof(hdr), &bytesRead);
 
@@ -1217,7 +1231,7 @@
 	
 	// Set it up...
 	ReadGatherStream &rreordered(*((ReadGatherStream*)reordered.get()));
-	int component = rreordered.AddComponent(pStream);
+	size_t component = rreordered.AddComponent(pStream);
 	// Send out the block index
 	rreordered.AddBlock(component, blockIndexSize, true, blockIndexLoc);
 	// And then the rest of the file
@@ -1339,7 +1353,7 @@
 			
 			// Decrypt the encrypted section
 			file_BlockIndexEntryEnc entryEnc;
-			int sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
+			size_t sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
 					entry.mEnEnc, sizeof(entry.mEnEnc));
 			if(sectionSize != sizeof(entryEnc))
 			{
@@ -1478,7 +1492,7 @@
 //		Created: 25/11/04
 //
 // --------------------------------------------------------------------------
-void BackupStoreFile::EncodingBuffer::Allocate(int Size)
+void BackupStoreFile::EncodingBuffer::Allocate(size_t Size)
 {
 	ASSERT(mpBuffer == 0);
 	uint8_t *buffer = (uint8_t*)BackupStoreFile::CodingChunkAlloc(Size);
@@ -1500,7 +1514,7 @@
 //		Created: 25/11/04
 //
 // --------------------------------------------------------------------------
-void BackupStoreFile::EncodingBuffer::Reallocate(int NewSize)
+void BackupStoreFile::EncodingBuffer::Reallocate(size_t NewSize)
 {
 	BOX_TRACE("Reallocating EncodingBuffer from " << mBufferSize <<
 		" to " << NewSize);

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFile.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -81,8 +81,8 @@
 		~DecodedStream();
 
 		// Stream functions		
-		virtual int Read(void *pBuffer, int NBytes, int Timeout);
-		virtual void Write(const void *pBuffer, int NBytes);
+		virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout);
+		virtual void Write(const void *pBuffer, size_t NBytes);
 		virtual bool StreamDataLeft();
 		virtual bool StreamClosed();
 		
@@ -106,10 +106,10 @@
 		void *mpBlockIndex;
 		uint8_t *mpEncodedData;
 		uint8_t *mpClearData;
-		int mClearDataSize;
-		int mCurrentBlock;
-		int mCurrentBlockClearSize;
-		int mPositionInCurrentBlock;
+		size_t mClearDataSize;
+		int64_t mCurrentBlock;
+		size_t mCurrentBlockClearSize;
+		size_t mPositionInCurrentBlock;
 		uint64_t mEntryIVBase;
 #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE
 		bool mIsOldVersion;
@@ -153,14 +153,14 @@
 #endif
 
 	// Allocation of properly aligning chunks for decoding and encoding chunks
-	inline static void *CodingChunkAlloc(int Size)
+	inline static void *CodingChunkAlloc(size_t Size)
 	{
 		uint8_t *a = (uint8_t*)malloc((Size) + (BACKUPSTOREFILE_CODING_BLOCKSIZE * 3));
 		if(a == 0) return 0;
 		// Align to main block size
-		ASSERT(sizeof(unsigned long) >= sizeof(void*));	// make sure casting the right pointer size
+		ASSERT(sizeof(size_t) >= sizeof(void*));	// make sure casting the right pointer size
 		uint8_t adjustment = BACKUPSTOREFILE_CODING_BLOCKSIZE
-							  - (uint8_t)(((unsigned long)a) % BACKUPSTOREFILE_CODING_BLOCKSIZE);
+							  - (uint8_t)(((size_t)a) % BACKUPSTOREFILE_CODING_BLOCKSIZE);
 		uint8_t *b = (a + adjustment);
 		// Store adjustment
 		*b = adjustment;
@@ -170,8 +170,8 @@
 	inline static void CodingChunkFree(void *Block)
 	{
 		// Check alignment is as expected
-		ASSERT(sizeof(unsigned long) >= sizeof(void*));	// make sure casting the right pointer size
-		ASSERT((uint8_t)(((unsigned long)Block) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET);
+		ASSERT(sizeof(size_t) >= sizeof(void*));	// make sure casting the right pointer size
+		ASSERT((uint8_t)(((size_t)Block) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET);
 		uint8_t *a = (uint8_t*)Block;
 		a -= BACKUPSTOREFILE_CODING_OFFSET;
 		// Adjust downwards...
@@ -192,23 +192,23 @@
 		EncodingBuffer(const EncodingBuffer &);
 		EncodingBuffer &operator=(const EncodingBuffer &);
 	public:
-		void Allocate(int Size);
-		void Reallocate(int NewSize);
+		void Allocate(size_t Size);
+		void Reallocate(size_t NewSize);
 		
 		uint8_t *mpBuffer;
-		int mBufferSize;
+		size_t mBufferSize;
 	};
-	static int MaxBlockSizeForChunkSize(int ChunkSize);
-	static int EncodeChunk(const void *Chunk, int ChunkSize, BackupStoreFile::EncodingBuffer &rOutput);
+	static size_t MaxBlockSizeForChunkSize(size_t ChunkSize);
+	static size_t EncodeChunk(const void *Chunk, size_t ChunkSize, BackupStoreFile::EncodingBuffer &rOutput);
 
 	// Caller should know how big the output size is, but also allocate a bit more memory to cover various
 	// overheads allowed for in checks
-	static inline int OutputBufferSizeForKnownOutputSize(int KnownChunkSize)
+	static inline size_t OutputBufferSizeForKnownOutputSize(size_t KnownChunkSize)
 	{
 		// Plenty big enough
 		return KnownChunkSize + 256;
 	}
-	static int DecodeChunk(const void *Encoded, int EncodedSize, void *Output, int OutputSize);
+	static size_t DecodeChunk(const void *Encoded, size_t EncodedSize, void *Output, size_t OutputSize);
 
 	// Statisitics, not designed to be completely reliable	
 	static void ResetStats();

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbDiff.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbDiff.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbDiff.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -79,7 +79,12 @@
 	}
 	int64_t diff1NumBlocks = box_ntoh64(diff1IdxHdr.mNumBlocks);
 	// Allocate some memory
-	int64_t *diff1BlockStartPositions = (int64_t*)::malloc((diff1NumBlocks + 1) * sizeof(int64_t));
+	uint64_t bytesToMalloc = (diff1NumBlocks + 1) * sizeof(int64_t);
+	if(bytesToMalloc >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	int64_t *diff1BlockStartPositions = (int64_t*)::malloc(static_cast<size_t>(bytesToMalloc));
 	if(diff1BlockStartPositions == 0)
 	{
 		throw std::bad_alloc();
@@ -87,7 +92,7 @@
 
 	// Buffer data
 	void *buffer = 0;
-	int bufferSize = 0;	
+	size_t bufferSize = 0;
 	
 	try
 	{
@@ -172,7 +177,7 @@
 
 			// What do to next about copying data
 			bool copyBlock = false;
-			int copySize = 0;
+			size_t copySize = 0;
 			int64_t copyFrom = 0;
 			bool fromFileDiff1 = false;
 	
@@ -191,24 +196,29 @@
 			else
 			{
 				// Block isn't present here -- is it present in the old one?
-				int64_t blockIndex = 0 - blockEn;
-				if(blockIndex < 0 || blockIndex > diff1NumBlocks)
+				int64_t blockIndex_ = 0 - blockEn;
+				if(blockIndex_ < 0 || blockIndex_ > diff1NumBlocks)
 				{
 					THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile)
 				}
+				if(blockIndex_ >= SIZE_MAX)
+				{
+					THROW_EXCEPTION(CommonException, Internal)
+				}
+				size_t blockIndex = static_cast<size_t>(blockIndex_);
 				if(diff1BlockStartPositions[blockIndex] > 0)
 				{
 					// Block is in the old diff file, copy it across
 					copyBlock = true;
 					copyFrom = diff1BlockStartPositions[blockIndex];
-					int nb = blockIndex + 1;
+					size_t nb = blockIndex + 1;
 					while(diff1BlockStartPositions[nb] <= 0)
 					{
 						// This is safe, because the last entry will terminate it properly!
 						++nb;
-						ASSERT(nb <= diff1NumBlocks);
+						ASSERT((int64_t)nb <= diff1NumBlocks);
 					}
-					copySize = diff1BlockStartPositions[nb] - copyFrom;
+					copySize = static_cast<size_t>(diff1BlockStartPositions[nb] - copyFrom);
 					fromFileDiff1 = true;
 				}
 			}
@@ -280,16 +290,17 @@
 			if(blockEn <= 0)
 			{
 				int64_t blockIndex = 0 - blockEn;
+				ASSERT(blockIndex < SIZE_MAX);
 				// In another file. Need to translate this against the other diff
 				if(diff1BlockStartPositions[blockIndex] > 0)
 				{
 					// Block is in the first diff file, stick in size
-					int nb = blockIndex + 1;
+					size_t nb = static_cast<size_t>(blockIndex + 1);
 					while(diff1BlockStartPositions[nb] <= 0)
 					{
 						// This is safe, because the last entry will terminate it properly!
 						++nb;
-						ASSERT(nb <= diff1NumBlocks);
+						ASSERT((int64_t)nb <= diff1NumBlocks);
 					}
 					int64_t size = diff1BlockStartPositions[nb] - diff1BlockStartPositions[blockIndex];
 					e.mEncodedSize = box_hton64(size);

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbIdx.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbIdx.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCmbIdx.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -31,8 +31,8 @@
 	BSFCombinedIndexStream(IOStream *pDiff);
 	~BSFCombinedIndexStream();
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 	virtual void Initialise(IOStream &rFrom);
@@ -174,7 +174,12 @@
 	
 	// Then... allocate memory for the list of sizes
 	mNumEntriesInFromFile = box_ntoh64(fromHdr.mNumBlocks);
-	mFromBlockSizes = (int64_t*)::malloc(mNumEntriesInFromFile * sizeof(int64_t));
+	uint64_t bytesToMalloc = mNumEntriesInFromFile * sizeof(int64_t);
+	if(bytesToMalloc >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	mFromBlockSizes = (int64_t*)::malloc(static_cast<size_t>(bytesToMalloc));
 	if(mFromBlockSizes == 0)
 	{
 		throw std::bad_alloc();
@@ -212,7 +217,7 @@
 //		Created: 8/7/04
 //
 // --------------------------------------------------------------------------
-int BSFCombinedIndexStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t BSFCombinedIndexStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Paranoia is good.
 	if(!mIsInitialised || mFromBlockSizes == 0 || mpDiff == 0)
@@ -220,13 +225,13 @@
 		THROW_EXCEPTION(BackupStoreException, Internal)
 	}
 	
-	int written = 0;
+	size_t written = 0;
 	
 	// Header output yet?
 	if(!mHeaderWritten)
 	{
 		// Enough space?
-		if(NBytes < (int)sizeof(mHeader)) return 0;
+		if(NBytes < sizeof(mHeader)) return 0;
 		
 		// Copy in
 		::memcpy(pBuffer, &mHeader, sizeof(mHeader));
@@ -238,17 +243,17 @@
 	}
 
 	// How many entries can be written?
-	int entriesToWrite = NBytes / sizeof(file_BlockIndexEntry);
-	if(entriesToWrite > mNumEntriesToGo)
+	size_t entriesToWrite = NBytes / sizeof(file_BlockIndexEntry);
+	if(entriesToWrite > static_cast<size_t>(mNumEntriesToGo))
 	{
-		entriesToWrite = mNumEntriesToGo;
+		entriesToWrite = static_cast<size_t>(mNumEntriesToGo);
 	}
 	
 	// Setup ready to go
 	file_BlockIndexEntry *poutput = (file_BlockIndexEntry*)(((uint8_t*)pBuffer) + written);
 
 	// Write entries
-	for(int b = 0; b < entriesToWrite; ++b)
+	for(size_t b = 0; b < entriesToWrite; ++b)
 	{
 		if(!mpDiff->ReadFullBuffer(&(poutput[b]), sizeof(file_BlockIndexEntry), 0))
 		{
@@ -256,11 +261,11 @@
 		}
 		
 		// Does this need adjusting?
-		int s = box_ntoh64(poutput[b].mEncodedSize);
+		int64_t s = box_ntoh64(poutput[b].mEncodedSize);
 		if(s <= 0)
 		{
 			// A reference to a block in the from file
-			int block = 0 - s;
+			int64_t block = 0 - s;
 			ASSERT(block >= 0);
 			if(block >= mNumEntriesInFromFile)
 			{
@@ -289,7 +294,7 @@
 //		Created: 8/7/04
 //
 // --------------------------------------------------------------------------
-void BSFCombinedIndexStream::Write(const void *pBuffer, int NBytes)
+void BSFCombinedIndexStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(BackupStoreException, StreamDoesntHaveRequiredFeatures)
 }

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCombine.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCombine.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileCombine.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -88,7 +88,7 @@
 		{
 			THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
 		}
-		int size = ntohl(size_s);
+		int32_t size = ntohl(size_s);
 		// Skip forward the size
 		rFrom.Seek(size, IOStream::SeekType_Relative);		
 	}
@@ -96,7 +96,12 @@
 	// Allocate memory for the block index of the From file
 	int64_t fromNumBlocks = box_ntoh64(fromHdr.mNumBlocks);
 	// NOTE: An extra entry is required so that the length of the last block can be calculated
-	FromIndexEntry *pFromIndex = (FromIndexEntry*)::malloc((fromNumBlocks+1) * sizeof(FromIndexEntry));
+	uint64_t bytesToMalloc = (fromNumBlocks+1) * sizeof(FromIndexEntry);
+	if(bytesToMalloc >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	FromIndexEntry *pFromIndex = (FromIndexEntry*)::malloc(static_cast<size_t>(bytesToMalloc));
 	if(pFromIndex == 0)
 	{
 		throw std::bad_alloc();
@@ -226,11 +231,11 @@
 	}
 	
 	// Record where the From file is
-	int64_t fromPos = rFrom.GetPosition();
+	IOStream::pos_type fromPos = rFrom.GetPosition();
 	
 	// Buffer data
 	void *buffer = 0;
-	int bufferSize = 0;
+	int64_t bufferSize = 0;
 	
 	try
 	{
@@ -248,7 +253,7 @@
 			int64_t encodedSize = box_ntoh64(en.mEncodedSize);
 			
 			// How much data will be read?
-			int32_t blockSize = 0;
+			int64_t blockSize = 0;
 			if(encodedSize > 0)
 			{
 				// The block is actually in the diff file
@@ -279,7 +284,11 @@
 					bufferSize = 0;
 				}
 				// Allocate new block
-				buffer = ::malloc(blockSize);
+				if(blockSize >= SIZE_MAX)
+				{
+					throw std::bad_alloc();
+				}
+				buffer = ::malloc(static_cast<size_t>(blockSize));
 				if(buffer == 0)
 				{
 					throw std::bad_alloc();
@@ -394,9 +403,9 @@
 				THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile)
 			}
 			// Calculate size. This operation is safe because of the extra entry at the end
-			int32_t blockSize = pFromIndex[blockIdx + 1].mFilePosition - pFromIndex[blockIdx].mFilePosition;
+			int64_t blockSize = pFromIndex[blockIdx + 1].mFilePosition - pFromIndex[blockIdx].mFilePosition;
 			// Then replace entry
-			en.mEncodedSize = box_hton64(((uint64_t)blockSize));
+			en.mEncodedSize = box_hton64(blockSize);
 		}
 		
 		// Write entry

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileDiff.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileDiff.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -53,7 +53,7 @@
 	int64_t NumBlocks, int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES],
 	DiffTimer *pDiffTimer);
 static void SetupHashTable(BlocksAvailableEntry *pIndex, int64_t NumBlocks, int32_t BlockSize, BlocksAvailableEntry **pHashTable);
-static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChecksum &fastSum, uint8_t *pBeginnings, uint8_t *pEndings, int Offset, int32_t BlockSize, int64_t FileBlockNumber,
+static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChecksum &fastSum, uint8_t *pBeginnings, uint8_t *pEndings, size_t Offset, int32_t BlockSize, int64_t FileBlockNumber,
 BlocksAvailableEntry *pIndex, std::map<int64_t, int64_t> &rFoundBlocks);
 static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksAvailableEntry *pIndex, int64_t NumBlocks, std::map<int64_t, int64_t> &rFoundBlocks, int64_t SizeOfInputFile);
 
@@ -302,7 +302,12 @@
 	//TODO: Verify that these sizes look reasonable
 	
 	// Allocate space for the index
-	BlocksAvailableEntry *pindex = (BlocksAvailableEntry*)::malloc(sizeof(BlocksAvailableEntry) * numBlocks);
+	uint64_t bytesToMalloc = sizeof(BlocksAvailableEntry) * numBlocks;
+	if(bytesToMalloc >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	BlocksAvailableEntry *pindex = (BlocksAvailableEntry*)::malloc(static_cast<size_t>(bytesToMalloc));
 	if(pindex == 0)
 	{
 		throw std::bad_alloc();
@@ -329,7 +334,7 @@
 			
 			// Decrypt the encrypted section
 			file_BlockIndexEntryEnc entryEnc;
-			int sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
+			size_t sectionSize = sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
 					entry.mEnEnc, sizeof(entry.mEnEnc));
 			if(sectionSize != sizeof(entryEnc))
 			{
@@ -545,7 +550,7 @@
 			// Setup block pointers
 			uint8_t *beginnings = pbuffer0;
 			uint8_t *endings = pbuffer1;
-			int offset = 0;
+			int32_t offset = 0;
 			
 			// Calculate the first checksum, ready for rolling
 			RollingChecksum rolling(beginnings, Sizes[s]);
@@ -553,7 +558,7 @@
 			// Then roll, until the file is exhausted
 			int64_t fileBlockNumber = 0;
 			int64_t fileOffset = 0;
-			int rollOverInitialBytes = 0;
+			int32_t rollOverInitialBytes = 0;
 			while(true)
 			{
 				if(maximumDiffingTime.HasExpired())
@@ -571,14 +576,14 @@
 				}
 				
 				// Load in another block of data, and record how big it is
-				int bytesInEndings = rFile.Read(endings, Sizes[s]);
+				int32_t bytesInEndings = rFile.Read(endings, Sizes[s]);
 				int tmp;
 
 				// Skip any bytes from a previous matched block
 				if(rollOverInitialBytes > 0 && offset < bytesInEndings)
 				{
-					int spaceLeft = bytesInEndings - offset;
-					int thisRoll = (rollOverInitialBytes > spaceLeft) ? spaceLeft : rollOverInitialBytes;
+					int32_t spaceLeft = bytesInEndings - offset;
+					int32_t thisRoll = (rollOverInitialBytes > spaceLeft) ? spaceLeft : rollOverInitialBytes;
 
 					rolling.RollForwardSeveral(beginnings+offset, endings+offset, Sizes[s], thisRoll);
 
@@ -605,8 +610,8 @@
 				{
 					// Skip over bigger ready-matched blocks completely
 					rollOverInitialBytes = tmp;
-					int spaceLeft = bytesInEndings - offset;
-					int thisRoll = (rollOverInitialBytes > spaceLeft) ? spaceLeft : rollOverInitialBytes;
+					int32_t spaceLeft = bytesInEndings - offset;
+					int32_t thisRoll = (rollOverInitialBytes > spaceLeft) ? spaceLeft : rollOverInitialBytes;
 
 					rolling.RollForwardSeveral(beginnings+offset, endings+offset, Sizes[s], thisRoll);
 
@@ -635,11 +640,11 @@
 							// any more comparisons, because these are pointless (as any more matches will be ignored when
 							// the recipe is generated) and just take up valuable processor time. Edge cases are
 							// especially nasty, using huge amounts of time and memory.
-							int skip = Sizes[s];
+							int32_t skip = Sizes[s];
 							if(offset < bytesInEndings && skip > 0)
 							{
-								int spaceLeft = bytesInEndings - offset;
-								int thisRoll = (skip > spaceLeft) ? spaceLeft : skip;
+								int32_t spaceLeft = bytesInEndings - offset;
+								int32_t thisRoll = (skip > spaceLeft) ? spaceLeft : skip;
 
 								rolling.RollForwardSeveral(beginnings+offset, endings+offset, Sizes[s], thisRoll);
 
@@ -802,7 +807,7 @@
 //
 // --------------------------------------------------------------------------
 static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChecksum &fastSum, uint8_t *pBeginnings, uint8_t *pEndings,
-	int Offset, int32_t BlockSize, int64_t FileBlockNumber, BlocksAvailableEntry *pIndex, std::map<int64_t, int64_t> &rFoundBlocks)
+	size_t Offset, int32_t BlockSize, int64_t FileBlockNumber, BlocksAvailableEntry *pIndex, std::map<int64_t, int64_t> &rFoundBlocks)
 {
 	// Check parameters
 	ASSERT(pBeginnings != 0);

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -48,7 +48,7 @@
 	  mSendData(true),
 	  mTotalBlocks(0),
 	  mAbsoluteBlockNumber(-1),
-	  mInstructionNumber(-1),
+	  mInstructionNumber(SIZE_MAX),
 	  mNumBlocks(0),
 	  mCurrentBlock(-1),
 	  mCurrentBlockEncodedSize(0),
@@ -150,7 +150,7 @@
 		
 		// Go through each instruction in the recipe and work out how many blocks
 		// it will add, and the max clear size of these blocks
-		int maxBlockClearSize = 0;
+		int32_t maxBlockClearSize = 0;
 		for(Recipe::size_type inst = 0; inst < pRecipe->size(); ++inst)
 		{
 			if((*pRecipe)[inst].mSpaceBefore > 0)
@@ -301,7 +301,7 @@
 	} while(rBlockSizeOut < BACKUP_FILE_MAX_BLOCK_SIZE && rNumBlocksOut > BACKUP_FILE_INCREASE_BLOCK_SIZE_AFTER);
 	
 	// Last block size
-	rLastBlockSizeOut = DataSize - ((rNumBlocksOut - 1) * rBlockSizeOut);
+	rLastBlockSizeOut = static_cast<int32_t>(DataSize - ((rNumBlocksOut - 1) * rBlockSizeOut));
 	
 	// Avoid small blocks?
 	if(rLastBlockSizeOut < BACKUP_FILE_AVOID_BLOCKS_LESS_THAN
@@ -313,7 +313,7 @@
 	}
 	
 	// checks!
-	ASSERT((((rNumBlocksOut-1) * rBlockSizeOut) + rLastBlockSizeOut) == DataSize);
+	ASSERT(static_cast<int64_t>(((rNumBlocksOut-1) * rBlockSizeOut) + rLastBlockSizeOut) == DataSize);
 	//TRACE4("CalcBlockSize, sz %lld, num %lld, blocksize %d, last %d\n", DataSize, rNumBlocksOut, (int32_t)rBlockSizeOut, (int32_t)rLastBlockSizeOut);
 }
 
@@ -327,7 +327,7 @@
 //		Created: 8/12/03
 //
 // --------------------------------------------------------------------------
-int BackupStoreFileEncodeStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t BackupStoreFileEncodeStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Check there's something to do.
 	if(mStatus == Status_Finished)
@@ -340,7 +340,7 @@
 		THROW_EXCEPTION(BackupStoreException, SignalReceived);
 	}
 
-	int bytesToRead = NBytes;
+	size_t bytesToRead = NBytes;
 	uint8_t *buffer = (uint8_t*)pBuffer;
 	
 	while(bytesToRead > 0 && mStatus != Status_Finished)
@@ -350,7 +350,7 @@
 			// Header or block listing phase -- send from the buffered stream
 		
 			// Send bytes from the data buffer
-			int b = mData.Read(buffer, bytesToRead, Timeout);
+			size_t b = mData.Read(buffer, bytesToRead, Timeout);
 			bytesToRead -= b;
 			buffer += b;
 			
@@ -400,7 +400,7 @@
 				if(mCurrentBlock >= mNumBlocks)
 				{
 					// Output extra blocks for this instruction and move forward in file
-					if(mInstructionNumber >= 0)
+					if(mInstructionNumber < SIZE_MAX)
 					{
 						SkipPreviousBlocksInInstruction();
 					}
@@ -409,14 +409,14 @@
 					++mInstructionNumber;
 					
 					// Skip instructions which don't contain any data
-					while(mInstructionNumber < static_cast<int64_t>(mpRecipe->size())
+					while(mInstructionNumber < mpRecipe->size()
 						&& (*mpRecipe)[mInstructionNumber].mSpaceBefore == 0)
 					{
 						SkipPreviousBlocksInInstruction();
 						++mInstructionNumber;
 					}
 					
-					if(mInstructionNumber >= static_cast<int64_t>(mpRecipe->size()))
+					if(mInstructionNumber >= mpRecipe->size())
 					{
 						// End of blocks, go to next phase
 						++mStatus;
@@ -442,7 +442,7 @@
 			if(mPositionInCurrentBlock < mCurrentBlockEncodedSize)
 			{
 				// How much data to put in the buffer?
-				int s = mCurrentBlockEncodedSize - mPositionInCurrentBlock;
+				size_t s = mCurrentBlockEncodedSize - mPositionInCurrentBlock;
 				if(s > bytesToRead) s = bytesToRead;
 				
 				// Copy it in
@@ -487,7 +487,7 @@
 	}
 
 	// Index of the first block in old file (being diffed from)
-	int firstIndex = mpRecipe->BlockPtrToIndex((*mpRecipe)[mInstructionNumber].mpStartBlock);
+	int64_t firstIndex = mpRecipe->BlockPtrToIndex((*mpRecipe)[mInstructionNumber].mpStartBlock);
 	
 	int64_t sizeToSkip = 0;
 
@@ -546,12 +546,12 @@
 void BackupStoreFileEncodeStream::EncodeCurrentBlock()
 {
 	// How big is the block, raw?
-	int blockRawSize = mBlockSize;
+	int32_t blockRawSize = mBlockSize;
 	if(mCurrentBlock == (mNumBlocks - 1))
 	{
 		blockRawSize = mLastBlockSize;
 	}
-	ASSERT(blockRawSize < mAllocatedBufferSize);
+	ASSERT((size_t)blockRawSize < mAllocatedBufferSize);
 
 	// Check file open
 	if(mpLogging == 0)
@@ -624,7 +624,7 @@
 	sBlowfishEncryptBlockEntry.SetIV(&iv);
 
 	// Encode the data
-	int encodedSize = sBlowfishEncryptBlockEntry.TransformBlock(entry.mEnEnc, sizeof(entry.mEnEnc), &entryEnc, sizeof(entryEnc));
+	size_t encodedSize = sBlowfishEncryptBlockEntry.TransformBlock(entry.mEnEnc, sizeof(entry.mEnEnc), &entryEnc, sizeof(entryEnc));
 	if(encodedSize != sizeof(entry.mEnEnc))
 	{
 		THROW_EXCEPTION(BackupStoreException, BlockEntryEncodingDidntGiveExpectedLength)
@@ -643,7 +643,7 @@
 //		Created: 8/12/03
 //
 // --------------------------------------------------------------------------
-void BackupStoreFileEncodeStream::Write(const void *pBuffer, int NBytes)
+void BackupStoreFileEncodeStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(BackupStoreException, CantWriteToEncodedFileStream)
 }

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileEncodeStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -81,8 +81,8 @@
 		ReadLoggingStream::Logger* pLogger = NULL,
 		RunStatusProvider* pRunStatusProvider = NULL);
 
-	virtual int Read(void *pBuffer, int NBytes, int Timeout);
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 
@@ -113,19 +113,19 @@
 	int64_t mTotalBlocks;				// Total number of blocks in the file
 	int64_t mAbsoluteBlockNumber;		// The absolute block number currently being output
 	// Instruction number
-	int64_t mInstructionNumber;
+	size_t mInstructionNumber;
 	// All the below are within the current instruction
 	int64_t mNumBlocks;					// number of blocks. Last one will be a different size to the rest in most cases
 	int64_t mCurrentBlock;
-	int32_t mCurrentBlockEncodedSize;
-	int32_t mPositionInCurrentBlock;	// for reading out
+	size_t mCurrentBlockEncodedSize;
+	size_t mPositionInCurrentBlock;	// for reading out
 	int32_t mBlockSize;					// Basic block size of most of the blocks in the file
 	int32_t mLastBlockSize;				// the size (unencoded) of the last block in the file
 	// Buffers
 	uint8_t *mpRawBuffer;				// buffer for raw data
 	BackupStoreFile::EncodingBuffer mEncodedBuffer;
 										// buffer for encoded data
-	int32_t mAllocatedBufferSize;		// size of above two allocated blocks
+	size_t mAllocatedBufferSize;		// size of above two allocated blocks
 	uint64_t mEntryIVBase;				// base for block entry IV
 };
 

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileRevDiff.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileRevDiff.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFileRevDiff.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -60,7 +60,12 @@
 	// For each block in the from file, we want to know it's index in the 
 	// diff file. Allocate memory for this information.
 	int64_t fromNumBlocks = box_ntoh64(hdr.mNumBlocks);
-	int64_t *pfromIndexInfo = (int64_t*)::malloc(fromNumBlocks * sizeof(int64_t));
+	uint64_t bytesToMalloc = fromNumBlocks * sizeof(int64_t);
+	if(bytesToMalloc >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	int64_t *pfromIndexInfo = (int64_t*)::malloc(static_cast<size_t>(bytesToMalloc));
 	if(pfromIndexInfo == 0)
 	{
 		throw std::bad_alloc();
@@ -68,7 +73,7 @@
 
 	// Buffer data
 	void *buffer = 0;
-	int bufferSize = 0;	
+	int64_t bufferSize = 0;	
 	
 	// flag
 	bool isCompletelyDifferent = true;
@@ -176,7 +181,11 @@
 						bufferSize = 0;
 					}
 					// Allocate new block
-					buffer = ::malloc(blockSize);
+					if(blockSize >= SIZE_MAX)
+					{
+						throw std::bad_alloc();
+					}
+					buffer = ::malloc(static_cast<size_t>(blockSize));
 					if(buffer == 0)
 					{
 						throw std::bad_alloc();

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilename.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilename.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilename.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -101,7 +101,7 @@
 #define BACKUPSTOREFILENAME_GET_SIZE(hdr)		(( ((uint8_t)((hdr)[0])) | ( ((uint8_t)((hdr)[1])) << 8)) >> 2)
 #define BACKUPSTOREFILENAME_GET_ENCODING(hdr)	(((hdr)[0]) & 0x3)
 
-#define BACKUPSTOREFILENAME_MAKE_HDR(hdr, size, encoding)		{uint16_t h = (((uint16_t)size) << 2) | (encoding); ((hdr)[0]) = h & 0xff; ((hdr)[1]) = h >> 8;}
+#define BACKUPSTOREFILENAME_MAKE_HDR(hdr, size, encoding)		{uint16_t h = (((uint16_t)size) << 2) | (uint16_t)(encoding); ((hdr)[0]) = h & 0xff; ((hdr)[1]) = h >> 8;}
 
 #endif // BACKUPSTOREFILENAME__H
 

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -187,10 +187,10 @@
 // Buffer for encoding and decoding -- do this all in one single buffer to
 // avoid lots of string allocation, which stuffs up memory usage.
 // These static memory vars are, of course, not thread safe, but we don't use threads.
-static int sEncDecBufferSize = 0;
+static size_t sEncDecBufferSize = 0;
 static MemoryBlockGuard<uint8_t *> *spEncDecBuffer = 0;
 
-static void EnsureEncDecBufferSize(int BufSize)
+static void EnsureEncDecBufferSize(size_t BufSize)
 {
 	if(spEncDecBuffer == 0)
 	{
@@ -228,7 +228,7 @@
 void BackupStoreFilenameClear::EncryptClear(const std::string &rToEncode, CipherContext &rCipherContext, int StoreAsEncoding)
 {
 	// Work out max size
-	int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rToEncode.size()) + 4;
+	size_t maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rToEncode.size()) + 4;
 	
 	// Make sure encode/decode buffer has enough space
 	EnsureEncDecBufferSize(maxOutSize);
@@ -237,7 +237,7 @@
 	uint8_t *buffer = *spEncDecBuffer;
 	
 	// Encode -- do entire block in one go
-	int encSize = rCipherContext.TransformBlock(buffer + 2, sEncDecBufferSize - 2, rToEncode.c_str(), rToEncode.size());
+	size_t encSize = rCipherContext.TransformBlock(buffer + 2, sEncDecBufferSize - 2, rToEncode.c_str(), rToEncode.size());
 	// and add in header size
 	encSize += 2;
 	
@@ -262,7 +262,7 @@
 	const std::string& rEncoded = GetEncodedFilename();
 
 	// Work out max size
-	int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rEncoded.size()) + 4;
+	size_t maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rEncoded.size()) + 4;
 	
 	// Make sure encode/decode buffer has enough space
 	EnsureEncDecBufferSize(maxOutSize);
@@ -272,7 +272,7 @@
 	
 	// Decrypt
 	const char *str = rEncoded.c_str() + 2;
-	int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, rEncoded.size() - 2);
+	size_t sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, rEncoded.size() - 2);
 	
 	// Assign to this
 	mClearFilename.assign((char*)buffer, sizeOut);
@@ -304,7 +304,7 @@
 //		Created: 1/12/03
 //
 // --------------------------------------------------------------------------
-void BackupStoreFilenameClear::SetBlowfishKey(const void *pKey, int KeyLength, const void *pIV, int IVLength)
+void BackupStoreFilenameClear::SetBlowfishKey(const void *pKey, int8_t KeyLength, const void *pIV, int8_t IVLength)
 {
 	// Initialisation vector not used. Can't use a different vector for each filename as
 	// that would stop comparisions on the server working.

Modified: box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/backupclient/BackupStoreFilenameClear.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -42,7 +42,7 @@
 	void SetClearFilename(const std::string &rToEncode);
 
 	// Setup for encryption of filenames	
-	static void SetBlowfishKey(const void *pKey, int KeyLength, const void *pIV, int IVLength);
+	static void SetBlowfishKey(const void *pKey, int8_t KeyLength, const void *pIV, int8_t IVLength);
 	static void SetEncodingMethod(int Method);
 	
 protected:

Modified: box/invisnet/vs2010/0.11/lib/common/Archive.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/Archive.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/Archive.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -67,7 +67,7 @@
 	}
 	void Write(const std::string &Item)
 	{
-		int size = Item.size();
+		int size = static_cast<int>(Item.size());
 		Write(size);
 		mrStream.Write(Item.c_str(), size);
 	}
@@ -119,7 +119,7 @@
 	{
 		int privItem;
 		Read(privItem);
-		rItemOut = privItem;
+		rItemOut = static_cast<uint8_t>(privItem);
 	}
 	void Read(std::string &rItemOut)
 	{

Modified: box/invisnet/vs2010/0.11/lib/common/BufferedStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/BufferedStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/BufferedStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -36,13 +36,13 @@
 //		Created: 2007/01/16
 //
 // --------------------------------------------------------------------------
-int BufferedStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t BufferedStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	if (mBufferSize == mBufferPosition)
 	{
 		// buffer is empty, fill it.
 
-		int numBytesRead = mrSource.Read(mBuffer, sizeof(mBuffer), 
+		size_t numBytesRead = mrSource.Read(mBuffer, sizeof(mBuffer), 
 			Timeout);
 
 		if (numBytesRead < 0)
@@ -53,7 +53,7 @@
 		mBufferSize = numBytesRead;
 	}
 
-	int sizeToReturn = mBufferSize - mBufferPosition;
+	size_t sizeToReturn = mBufferSize - mBufferPosition;
 
 	if (sizeToReturn > NBytes)
 	{
@@ -96,7 +96,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-void BufferedStream::Write(const void *pBuffer, int NBytes)
+void BufferedStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, NotSupported);
 }

Modified: box/invisnet/vs2010/0.11/lib/common/BufferedStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/BufferedStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/BufferedStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -17,15 +17,15 @@
 private:
 	IOStream& mrSource;
 	char mBuffer[4096];
-	int  mBufferSize;
-	int  mBufferPosition;
+	size_t  mBufferSize;
+	size_t  mBufferPosition;
 
 public:
 	BufferedStream(IOStream& rSource);
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(IOStream::pos_type Offset, int SeekType);
 	virtual void Close();

Modified: box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -56,14 +56,14 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-int CollectInBufferStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t CollectInBufferStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	if(mInWritePhase != false) { THROW_EXCEPTION(CommonException, CollectInBufferStreamNotInCorrectPhase) }
 	
 	// Adjust to number of bytes left
 	if(NBytes > (mBytesInBuffer - mReadPosition))
 	{
-		NBytes = (mBytesInBuffer - mReadPosition);
+		NBytes = static_cast<size_t>(mBytesInBuffer - mReadPosition);
 	}
 	ASSERT(NBytes >= 0);
 	if(NBytes <= 0) return 0;	// careful now
@@ -98,7 +98,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-void CollectInBufferStream::Write(const void *pBuffer, int NBytes)
+void CollectInBufferStream::Write(const void *pBuffer, size_t NBytes)
 {
 	if(mInWritePhase != true) { THROW_EXCEPTION(CommonException, CollectInBufferStreamNotInCorrectPhase) }
 	
@@ -106,14 +106,14 @@
 	if((mBytesInBuffer + NBytes) > mBufferSize)
 	{
 		// Need to reallocate... what's the block size we'll use?
-		int allocateBlockSize = mBufferSize;
+		size_t allocateBlockSize = mBufferSize;
 		if(allocateBlockSize > MAX_BUFFER_ADDITION)
 		{
 			allocateBlockSize = MAX_BUFFER_ADDITION;
 		}
 		
 		// Write it the easy way. Although it's not the most efficient...
-		int newSize = mBufferSize;
+		size_t newSize = mBufferSize;
 		while(newSize < (mBytesInBuffer + NBytes))
 		{
 			newSize += allocateBlockSize;
@@ -157,7 +157,7 @@
 {
 	if(mInWritePhase != false) { THROW_EXCEPTION(CommonException, CollectInBufferStreamNotInCorrectPhase) }
 	
-	int newPos = 0;
+	pos_type newPos = 0;
 	switch(SeekType)
 	{
 	case IOStream::SeekType_Absolute:
@@ -175,7 +175,7 @@
 	}
 	
 	// Make sure it doesn't go over
-	if(newPos > mBytesInBuffer)
+	if(newPos > static_cast<pos_type>(mBytesInBuffer))
 	{
 		newPos = mBytesInBuffer;
 	}
@@ -199,7 +199,7 @@
 // --------------------------------------------------------------------------
 bool CollectInBufferStream::StreamDataLeft()
 {
-	return mInWritePhase?(false):(mReadPosition < mBytesInBuffer);
+	return mInWritePhase?(false):(mReadPosition < static_cast<pos_type>(mBytesInBuffer));
 }
 
 // --------------------------------------------------------------------------
@@ -252,7 +252,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-int CollectInBufferStream::GetSize() const
+size_t CollectInBufferStream::GetSize() const
 {
 	return mBytesInBuffer;
 }

Modified: box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/CollectInBufferStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -32,9 +32,9 @@
 	CollectInBufferStream(const IOStream &);
 public:
 
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(pos_type Offset, int SeekType);
 	virtual bool StreamDataLeft();
@@ -45,14 +45,14 @@
 	void Reset();
 	
 	void *GetBuffer() const;
-	int GetSize() const;
+	size_t GetSize() const;
 	bool IsSetForReading() const {return !mInWritePhase;}
 
 private:
 	MemoryBlockGuard<char*> mBuffer;
-	int mBufferSize;
-	int mBytesInBuffer;
-	int mReadPosition;
+	size_t mBufferSize;
+	size_t mBytesInBuffer;
+	pos_type mReadPosition;
 	bool mInWritePhase;
 };
 

Modified: box/invisnet/vs2010/0.11/lib/common/ExcludeList.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ExcludeList.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ExcludeList.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -84,7 +84,7 @@
 
 	for (std::string::iterator i = output.begin(); i != output.end(); i++)
 	{
-		*i = tolower(*i);
+		*i = static_cast<std::string::iterator::value_type>(tolower(*i));
 	}
 
 	return output;
@@ -103,7 +103,7 @@
 
 	for (std::string::iterator i = output.begin(); i != output.end(); i++)
 	{
-		*i = tolower(*i);
+		*i = static_cast<std::string::iterator::value_type>(tolower(*i));
 	}
 
 	return output;

Modified: box/invisnet/vs2010/0.11/lib/common/ExcludeList.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ExcludeList.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ExcludeList.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -48,8 +48,8 @@
 	bool IsExcluded(const std::string &rTest) const;
 	
 	// Mainly for tests
-	unsigned int SizeOfDefiniteList() const {return mDefinite.size();}
-	unsigned int SizeOfRegexList() const
+	size_t SizeOfDefiniteList() const {return mDefinite.size();}
+	size_t SizeOfRegexList() const
 #ifdef HAVE_REGEX_SUPPORT
 		{return mRegex.size();}
 #else

Modified: box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -175,15 +175,15 @@
 	else
 	{
 		// Remove whitespace
-		int size = r.size();
-		int begin = 0;
+		size_t size = r.size();
+		size_t begin = 0;
 		while(begin < size && iw(r[begin]))
 		{
 			begin++;
 		}
 		
 		// Check for comment char, but char before must be whitespace
-		int end = begin;
+		size_t end = begin;
 		while(end < size)
 		{
 			if(r[end] == '#' && (end == 0 || (iw(r[end-1]))))

Modified: box/invisnet/vs2010/0.11/lib/common/FileStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/FileStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/FileStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -162,7 +162,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-int FileStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t FileStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	if(mOSFileHandle == INVALID_FILE) 
 	{
@@ -170,12 +170,13 @@
 	}
 
 #ifdef WIN32
+	ASSERT(NBytes <= std::numeric_limits<DWORD>::max());
 	int r;
 	DWORD numBytesRead = 0;
 	BOOL valid = ReadFile(
 		this->mOSFileHandle,
 		pBuffer,
-		NBytes,
+		static_cast<DWORD>(NBytes),
 		&numBytesRead,
 		NULL
 		);
@@ -243,7 +244,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-void FileStream::Write(const void *pBuffer, int NBytes)
+void FileStream::Write(const void *pBuffer, size_t NBytes)
 {
 	if(mOSFileHandle == INVALID_FILE) 
 	{
@@ -251,11 +252,12 @@
 	}
 
 #ifdef WIN32
+	ASSERT(NBytes <= std::numeric_limits<DWORD>::max());
 	DWORD numBytesWritten = 0;
 	BOOL res = WriteFile(
 		this->mOSFileHandle,
 		pBuffer,
-		NBytes,
+		static_cast<DWORD>(NBytes),
 		&numBytesWritten,
 		NULL
 		);
@@ -423,7 +425,7 @@
 	char buf2[2048];
 	while(StreamDataLeft() && rOther.StreamDataLeft())
 	{
-		int readSize = rOther.Read(buf1, sizeof(buf1), Timeout);
+		size_t readSize = rOther.Read(buf1, sizeof(buf1), Timeout);
 		otherSize += readSize;
 		
 		if(Read(buf2, readSize) != readSize ||

Modified: box/invisnet/vs2010/0.11/lib/common/FileStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/FileStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/FileStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -38,9 +38,9 @@
 	
 	virtual ~FileStream();
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(IOStream::pos_type Offset, int SeekType);
 	virtual void Close();
@@ -58,6 +58,13 @@
 
 	// for debugging..
 	std::string mFileName;
+
+public:
+	template <class T>
+	inline T Read(void *pBuffer, T NBytes, int Timeout = IOStream::TimeOutInfinite)
+	{
+		return IOStream::Read(pBuffer,NBytes,Timeout);
+	}
 };
 
 

Modified: box/invisnet/vs2010/0.11/lib/common/Guards.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/Guards.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/Guards.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -77,7 +77,7 @@
 class MemoryBlockGuard
 {
 public:
-	MemoryBlockGuard(int BlockSize)
+	MemoryBlockGuard(size_t BlockSize)
 		: mpBlock(::malloc(BlockSize))
 	{
 		if(mpBlock == 0)
@@ -101,7 +101,7 @@
 		return (type)mpBlock;
 	}
 	
-	void Resize(int NewSize)
+	void Resize(size_t NewSize)
 	{
 		void *ptrn = ::realloc(mpBlock, NewSize);
 		if(ptrn == 0)

Modified: box/invisnet/vs2010/0.11/lib/common/IOStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/IOStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/IOStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -132,15 +132,15 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-bool IOStream::ReadFullBuffer(void *pBuffer, int NBytes, int *pNBytesRead, int Timeout)
+bool IOStream::mReadFullBuffer(void *pBuffer, size_t NBytes, size_t *pNBytesRead, int Timeout)
 {
-	int bytesToGo = NBytes;
+	size_t bytesToGo = NBytes;
 	char *buffer = (char*)pBuffer;
 	if(pNBytesRead) (*pNBytesRead) = 0;
 	
 	while(bytesToGo > 0)
 	{
-		int bytesRead = Read(buffer, bytesToGo, Timeout);
+		size_t bytesRead = Read(buffer, bytesToGo, Timeout);
 		if(bytesRead == 0)
 		{
 			// Timeout or something
@@ -194,7 +194,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-bool IOStream::CopyStreamTo(IOStream &rCopyTo, int Timeout, int BufferSize)
+bool IOStream::CopyStreamTo(IOStream &rCopyTo, int Timeout, size_t BufferSize)
 {
 	// Make sure there's something to do before allocating that buffer
 	if(!StreamDataLeft())
@@ -209,7 +209,7 @@
 	while(StreamDataLeft())
 	{
 		// Read some data
-		int bytes = Read(buffer, BufferSize, Timeout);
+		size_t bytes = Read(buffer, BufferSize, Timeout);
 		if(bytes == 0 && StreamDataLeft())
 		{
 			return false;	// incomplete, timed out

Modified: box/invisnet/vs2010/0.11/lib/common/IOStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/IOStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/IOStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -45,9 +45,9 @@
 	// Timeout in milliseconds
 	// Read may return 0 -- does not mean end of stream.
 	typedef int64_t pos_type;
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite) = 0;
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite) = 0;
 	virtual pos_type BytesLeftToRead();	// may return IOStream::SizeOfStreamUnknown (and will for most stream types)
-	virtual void Write(const void *pBuffer, int NBytes) = 0;
+	virtual void Write(const void *pBuffer, size_t NBytes) = 0;
 	virtual void Write(const char *pBuffer);
 	virtual void WriteAllBuffered();
 	virtual pos_type GetPosition() const;
@@ -60,11 +60,41 @@
 	virtual bool StreamClosed() = 0;
 	
 	// Utility functions
-	bool ReadFullBuffer(void *pBuffer, int NBytes, int *pNBytesRead, int Timeout = IOStream::TimeOutInfinite);
-	bool CopyStreamTo(IOStream &rCopyTo, int Timeout = IOStream::TimeOutInfinite, int BufferSize = 1024);
+	bool CopyStreamTo(IOStream &rCopyTo, int Timeout = IOStream::TimeOutInfinite, size_t BufferSize = 1024);
 	void Flush(int Timeout = IOStream::TimeOutInfinite);
 	
 	static int ConvertSeekTypeToOSWhence(int SeekType);
+
+
+	// things to make the compiler happier
+	template <class T>
+	inline T Read(void *pBuffer, T NBytes, int Timeout = IOStream::TimeOutInfinite)
+	{
+		if (NBytes >= SIZE_MAX)
+			throw std::bad_cast();
+		return static_cast<T>(Read(pBuffer,static_cast<size_t>(NBytes),Timeout));
+	}
+	template <class T>
+	inline void Write(const void *pBuffer, T NBytes)
+	{
+		if (NBytes >= SIZE_MAX)
+			throw std::bad_cast();
+		Write(pBuffer,static_cast<size_t>(NBytes));
+	}
+	template <class T>
+	inline bool ReadFullBuffer(void *pBuffer, T NBytes, void *pNBytesRead, int Timeout = IOStream::TimeOutInfinite)
+	{
+		if (NBytes >= SIZE_MAX)
+			throw std::bad_cast();
+		size_t n;
+		bool b = mReadFullBuffer(pBuffer,static_cast<size_t>(NBytes),&n,Timeout);
+		if(pNBytesRead)
+			*static_cast<T*>(pNBytesRead) = static_cast<T>(n);
+		return b;
+	}
+
+protected:
+	bool mReadFullBuffer(void *pBuffer, size_t NBytes, size_t *pNBytesRead, int Timeout = IOStream::TimeOutInfinite);
 };
 
 

Modified: box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -113,7 +113,7 @@
 		// Read more in?
 		if(!foundLineEnd && mBufferBegin >= mBytesInBuffer && !mPendingEOF)
 		{
-			int bytes = mrStream.Read(mBuffer, sizeof(mBuffer), Timeout);
+			size_t bytes = mrStream.Read(mBuffer, sizeof(mBuffer), Timeout);
 			
 			// Adjust buffer info
 			mBytesInBuffer = bytes;
@@ -151,8 +151,8 @@
 	else
 	{
 		// Check for comment char, but char before must be whitespace
-		int end = 0;
-		int size = r.size();
+		size_t end = 0;
+		size_t size = r.size();
 		while(end < size)
 		{
 			if(r[end] == '#' && (end == 0 || (iw(r[end-1]))))
@@ -163,7 +163,7 @@
 		}
 		
 		// Remove whitespace
-		int begin = 0;
+		size_t begin = 0;
 		while(begin < size && iw(r[begin]))
 		{
 			begin++;
@@ -193,7 +193,7 @@
 void IOStreamGetLine::DetachFile()
 {
 	// Adjust file pointer
-	int bytesOver = mBytesInBuffer - mBufferBegin;
+	size_t bytesOver = mBytesInBuffer - mBufferBegin;
 	ASSERT(bytesOver >= 0);
 	if(bytesOver > 0)
 	{
@@ -213,9 +213,9 @@
 //		Created: 22/12/04
 //
 // --------------------------------------------------------------------------
-void IOStreamGetLine::IgnoreBufferedData(int BytesToIgnore)
+void IOStreamGetLine::IgnoreBufferedData(size_t BytesToIgnore)
 {
-	int bytesInBuffer = mBytesInBuffer - mBufferBegin;
+	size_t bytesInBuffer = mBytesInBuffer - mBufferBegin;
 	if(BytesToIgnore < 0 || BytesToIgnore > bytesInBuffer)
 	{
 		THROW_EXCEPTION(CommonException, IOStreamGetLineNotEnoughDataToIgnore)

Modified: box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/IOStreamGetLine.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -53,16 +53,16 @@
 	// For doing interesting stuff with the remaining data...
 	// Be careful with this!
 	const void *GetBufferedData() const {return mBuffer + mBufferBegin;}
-	int GetSizeOfBufferedData() const {return mBytesInBuffer - mBufferBegin;}
-	void IgnoreBufferedData(int BytesToIgnore);
+	size_t GetSizeOfBufferedData() const {return mBytesInBuffer - mBufferBegin;}
+	void IgnoreBufferedData(size_t BytesToIgnore);
 	IOStream &GetUnderlyingStream() {return mrStream;}
 	
 private:
 	char mBuffer[IOSTREAMGETLINE_BUFFER_SIZE];
 	IOStream &mrStream;
 	int mLineNumber;
-	int mBufferBegin;
-	int mBytesInBuffer;
+	size_t mBufferBegin;
+	size_t mBytesInBuffer;
 	bool mPendingEOF;
 	bool mEOF;
 	std::string mPendingString;

Modified: box/invisnet/vs2010/0.11/lib/common/MemBlockStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/MemBlockStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/MemBlockStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -26,7 +26,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-MemBlockStream::MemBlockStream(const void *pBuffer, int Size)
+MemBlockStream::MemBlockStream(const void *pBuffer, size_t Size)
 	: mpBuffer((char*)pBuffer),
 	  mBytesInBuffer(Size),
 	  mReadPosition(0)
@@ -108,12 +108,12 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-int MemBlockStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t MemBlockStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Adjust to number of bytes left
 	if(NBytes > (mBytesInBuffer - mReadPosition))
 	{
-		NBytes = (mBytesInBuffer - mReadPosition);
+		NBytes = static_cast<size_t>(mBytesInBuffer - mReadPosition);
 	}
 	ASSERT(NBytes >= 0);
 	if(NBytes <= 0) return 0;	// careful now
@@ -146,7 +146,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-void MemBlockStream::Write(const void *pBuffer, int NBytes)
+void MemBlockStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, MemBlockStreamNotSupported)
 }
@@ -175,7 +175,7 @@
 // --------------------------------------------------------------------------
 void MemBlockStream::Seek(pos_type Offset, int SeekType)
 {
-	int newPos = 0;
+	pos_type newPos = 0;
 	switch(SeekType)
 	{
 	case IOStream::SeekType_Absolute:
@@ -193,7 +193,7 @@
 	}
 	
 	// Make sure it doesn't go over
-	if(newPos > mBytesInBuffer)
+	if(newPos > static_cast<pos_type>(mBytesInBuffer))
 	{
 		newPos = mBytesInBuffer;
 	}
@@ -217,7 +217,7 @@
 // --------------------------------------------------------------------------
 bool MemBlockStream::StreamDataLeft()
 {
-	return mReadPosition < mBytesInBuffer;
+	return mReadPosition < static_cast<pos_type>(mBytesInBuffer);
 }
 
 // --------------------------------------------------------------------------

Modified: box/invisnet/vs2010/0.11/lib/common/MemBlockStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/MemBlockStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/MemBlockStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -27,16 +27,16 @@
 class MemBlockStream : public IOStream
 {
 public:
-	MemBlockStream(const void *pBuffer, int Size);
+	MemBlockStream(const void *pBuffer, size_t Size);
 	MemBlockStream(const StreamableMemBlock &rBlock);
 	MemBlockStream(const CollectInBufferStream &rBuffer);
 	MemBlockStream(const MemBlockStream &rToCopy);
 	~MemBlockStream();
 public:
 
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(pos_type Offset, int SeekType);
 	virtual bool StreamDataLeft();
@@ -44,8 +44,8 @@
 
 private:
 	const char *mpBuffer;
-	int mBytesInBuffer;
-	int mReadPosition;
+	size_t mBytesInBuffer;
+	pos_type mReadPosition;
 };
 
 #endif // MEMBLOCKSTREAM__H

Modified: box/invisnet/vs2010/0.11/lib/common/PartialReadStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/PartialReadStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/PartialReadStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -57,7 +57,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-int PartialReadStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t PartialReadStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Finished?
 	if(mBytesLeft <= 0)
@@ -66,15 +66,15 @@
 	}
 
 	// Asking for more than is allowed?
-	if(NBytes > mBytesLeft)
+	if(static_cast<IOStream::pos_type>(NBytes) > mBytesLeft)
 	{
 		// Adjust downwards
-		NBytes = mBytesLeft;
+		NBytes = static_cast<size_t>(mBytesLeft);
 	}
 	
 	// Route the request to the source
-	int read = mrSource.Read(pBuffer, NBytes, Timeout);
-	ASSERT(read <= mBytesLeft);
+	size_t read = mrSource.Read(pBuffer, NBytes, Timeout);
+	ASSERT(static_cast<IOStream::pos_type>(read) <= mBytesLeft);
 	
 	// Adjust the count
 	mBytesLeft -= read;
@@ -104,7 +104,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-void PartialReadStream::Write(const void *pBuffer, int NBytes)
+void PartialReadStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, CantWriteToPartialReadStream)
 }

Modified: box/invisnet/vs2010/0.11/lib/common/PartialReadStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/PartialReadStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/PartialReadStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -31,9 +31,9 @@
 	PartialReadStream(const PartialReadStream &);
 	
 public:
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 

Modified: box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -65,12 +65,12 @@
 //		Created: 10/12/03
 //
 // --------------------------------------------------------------------------
-int ReadGatherStream::AddComponent(IOStream *pStream)
+size_t ReadGatherStream::AddComponent(IOStream *pStream)
 {
 	ASSERT(pStream != 0);
 
 	// Just add the component to the list, returning it's index.
-	int index = mComponents.size();
+	size_t index = mComponents.size();
 	mComponents.push_back(pStream);
 	return index;
 }
@@ -87,10 +87,10 @@
 //		Created: 10/12/03
 //
 // --------------------------------------------------------------------------
-void ReadGatherStream::AddBlock(int Component, pos_type Length, bool Seek, pos_type SeekTo)
+void ReadGatherStream::AddBlock(size_t Component, pos_type Length, bool Seek, pos_type SeekTo)
 {
 	// Check block
-	if(Component < 0 || Component >= (int)mComponents.size() || Length < 0 || SeekTo < 0)
+	if(Component < 0 || Component >= mComponents.size() || Length < 0 || SeekTo < 0)
 	{
 		THROW_EXCEPTION(CommonException, ReadGatherStreamAddingBadBlock);
 	}
@@ -117,9 +117,9 @@
 //		Created: 10/12/03
 //
 // --------------------------------------------------------------------------
-int ReadGatherStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t ReadGatherStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
-	int bytesToRead = NBytes;
+	size_t bytesToRead = NBytes;
 	uint8_t *buffer = (uint8_t*)pBuffer;
 	
 	while(bytesToRead > 0)
@@ -147,14 +147,14 @@
 		{
 			// Read!
 			pos_type s = mBlocks[mCurrentBlock].mLength - mPositionInCurrentBlock;
-			if(s > bytesToRead) s = bytesToRead;
+			if(s > static_cast<pos_type>(bytesToRead)) s = bytesToRead;
 			
 			pos_type r = mComponents[mBlocks[mCurrentBlock].mComponent]->Read(buffer, s, Timeout);
 			
 			// update variables
 			mPositionInCurrentBlock += r;
 			buffer += r;
-			bytesToRead -= r;
+			bytesToRead -= static_cast<size_t>(r);
 			mCurrentPosition += r;
 			
 			if(r != s)
@@ -213,7 +213,7 @@
 //		Created: 10/12/03
 //
 // --------------------------------------------------------------------------
-void ReadGatherStream::Write(const void *pBuffer, int NBytes)
+void ReadGatherStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, CannotWriteToReadGatherStream);
 }

Modified: box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ReadGatherStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -32,12 +32,12 @@
 	ReadGatherStream &operator=(const ReadGatherStream &);
 public:
 
-	int AddComponent(IOStream *pStream);
-	void AddBlock(int Component, pos_type Length, bool Seek = false, pos_type SeekTo = 0);
+	size_t AddComponent(IOStream *pStream);
+	void AddBlock(size_t Component, pos_type Length, bool Seek = false, pos_type SeekTo = 0);
 
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 	virtual pos_type GetPosition() const;
@@ -50,7 +50,7 @@
 	{
 		pos_type mLength;
 		pos_type mSeekTo;
-		int mComponent;
+		size_t mComponent;
 		bool mSeek;
 	} Block;
 	

Modified: box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -43,9 +43,9 @@
 //		Created: 2007/01/16
 //
 // --------------------------------------------------------------------------
-int ReadLoggingStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t ReadLoggingStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
-	int numBytesRead = mrSource.Read(pBuffer, NBytes, Timeout);
+	size_t numBytesRead = mrSource.Read(pBuffer, NBytes, Timeout);
 
 	if (numBytesRead > 0)
 	{
@@ -96,7 +96,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-void ReadLoggingStream::Write(const void *pBuffer, int NBytes)
+void ReadLoggingStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, NotSupported);
 }

Modified: box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ReadLoggingStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -37,9 +37,9 @@
 public:
 	ReadLoggingStream(IOStream& rSource, Logger& rLogger);
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(IOStream::pos_type Offset, int SeekType);
 	virtual void Close();

Modified: box/invisnet/vs2010/0.11/lib/common/SelfFlushingStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/SelfFlushingStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/SelfFlushingStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -41,7 +41,7 @@
 	SelfFlushingStream(const IOStream& rToCopy);
 	
 public:
-	virtual int Read(void *pBuffer, int NBytes,
+	virtual size_t Read(void *pBuffer, size_t NBytes,
 		int Timeout = IOStream::TimeOutInfinite)
 	{
 		return mrSource.Read(pBuffer, NBytes, Timeout);
@@ -50,7 +50,7 @@
 	{
 		return mrSource.BytesLeftToRead();
 	}
-	virtual void Write(const void *pBuffer, int NBytes)
+	virtual void Write(const void *pBuffer, size_t NBytes)
 	{
 		mrSource.Write(pBuffer, NBytes);
 	}

Modified: box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -40,7 +40,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-StreamableMemBlock::StreamableMemBlock(void *pBuffer, int Size)
+StreamableMemBlock::StreamableMemBlock(void *pBuffer, size_t Size)
 	: mpBuffer(0),
 	  mSize(0)
 {
@@ -56,7 +56,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-StreamableMemBlock::StreamableMemBlock(int Size)
+StreamableMemBlock::StreamableMemBlock(size_t Size)
 	: mpBuffer(0),
 	  mSize(0)
 {
@@ -89,7 +89,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-void StreamableMemBlock::Set(void *pBuffer, int Size)
+void StreamableMemBlock::Set(void *pBuffer, size_t Size)
 {
 	FreeBlock();
 	AllocateBlock(Size);
@@ -115,7 +115,11 @@
 	}
 	
 	// Allocate a new block (this way to be exception safe)
-	char *pblock = (char*)malloc(size);
+	if(size >= SIZE_MAX)
+	{
+		throw std::bad_alloc();
+	}
+	char *pblock = (char*)malloc(static_cast<size_t>(size));
 	if(pblock == 0)
 	{
 		throw std::bad_alloc();
@@ -141,7 +145,7 @@
 	// store...
 	ASSERT(mpBuffer == 0);
 	mpBuffer = pblock;
-	mSize = size;
+	mSize = static_cast<size_t>(size);
 }
 
 
@@ -200,7 +204,7 @@
 //		Created: 2003/09/05
 //
 // --------------------------------------------------------------------------
-void StreamableMemBlock::AllocateBlock(int Size)
+void StreamableMemBlock::AllocateBlock(size_t Size)
 {
 	ASSERT(mpBuffer == 0);
 	if(Size > 0)
@@ -223,7 +227,7 @@
 //		Created: 3/12/03
 //
 // --------------------------------------------------------------------------
-void StreamableMemBlock::ResizeBlock(int Size)
+void StreamableMemBlock::ResizeBlock(size_t Size)
 {
 	ASSERT(Size > 0);
 	if(Size > 0)
@@ -299,7 +303,8 @@
 // --------------------------------------------------------------------------
 void StreamableMemBlock::WriteToStream(IOStream &rStream) const
 {
-	int32_t sizenbo = htonl(mSize);
+	ASSERT(mSize <= (size_t)std::numeric_limits<int32_t>::max());
+	int32_t sizenbo = htonl(static_cast<int32_t>(mSize));
 	// Size
 	rStream.Write(&sizenbo, sizeof(sizenbo));
 	// Buffer

Modified: box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/StreamableMemBlock.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -24,13 +24,13 @@
 {
 public:
 	StreamableMemBlock();
-	StreamableMemBlock(int Size);
-	StreamableMemBlock(void *pBuffer, int Size);
+	StreamableMemBlock(size_t Size);
+	StreamableMemBlock(void *pBuffer, size_t Size);
 	StreamableMemBlock(const StreamableMemBlock &rToCopy);
 	~StreamableMemBlock();
 	
 	void Set(const StreamableMemBlock &rBlock);
-	void Set(void *pBuffer, int Size);
+	void Set(void *pBuffer, size_t Size);
 	void Set(IOStream &rStream, int Timeout);
 	StreamableMemBlock &operator=(const StreamableMemBlock &rBlock)
 	{
@@ -46,7 +46,7 @@
 	void *GetBuffer() const;
 	
 	// Size of block
-	int GetSize() const {return mSize;}
+	size_t GetSize() const {return mSize;}
 
 	// Buffer empty?
 	bool IsEmpty() const {return mSize == 0;}
@@ -56,15 +56,15 @@
 	
 	bool operator==(const StreamableMemBlock &rCompare) const;
 
-	void ResizeBlock(int Size);
+	void ResizeBlock(size_t Size);
 
 protected:	// be careful with these!
-	void AllocateBlock(int Size);
+	void AllocateBlock(size_t Size);
 	void FreeBlock();
 
 private:
 	void *mpBuffer;
-	int mSize;
+	size_t mSize;
 };
 
 #endif // STREAMABLEMEMBLOCK__H

Modified: box/invisnet/vs2010/0.11/lib/common/Utils.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/Utils.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/Utils.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -51,7 +51,7 @@
 	while(e = String.find_first_of(SplitOn, b), e != String.npos)
 	{
 		// Get this string
-		unsigned int len = e - b;
+		size_t len = e - b;
 		if(len >= 1)
 		{
 			rOutput.push_back(String.substr(b, len));

Modified: box/invisnet/vs2010/0.11/lib/common/ZeroStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ZeroStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ZeroStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -36,15 +36,15 @@
 //		Created: 2007/01/16
 //
 // --------------------------------------------------------------------------
-int ZeroStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t ZeroStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	ASSERT(NBytes > 0);
 
-	int bytesToRead = NBytes;
+	size_t bytesToRead = NBytes;
 	
-	if (bytesToRead > mSize - mPosition)
+	if (static_cast<IOStream::pos_type>(bytesToRead) > mSize - mPosition)
 	{
-		bytesToRead = mSize - mPosition;
+		bytesToRead = static_cast<size_t>(mSize - mPosition);
 	}
 
 	memset(pBuffer, 0, bytesToRead);
@@ -76,7 +76,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-void ZeroStream::Write(const void *pBuffer, int NBytes)
+void ZeroStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(CommonException, NotSupported);
 }

Modified: box/invisnet/vs2010/0.11/lib/common/ZeroStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/ZeroStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/common/ZeroStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -20,9 +20,9 @@
 public:
 	ZeroStream(IOStream::pos_type mSize);
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(IOStream::pos_type Offset, int SeekType);
 	virtual void Close();

Modified: box/invisnet/vs2010/0.11/lib/compress/Compress.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/compress/Compress.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/compress/Compress.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -87,8 +87,10 @@
 	//		Created: 5/12/03
 	//
 	// --------------------------------------------------------------------------
-	void Input(const void *pInBuffer, int InLength)
+	void Input(const void *pInBuffer, size_t InLength)
 	{
+		ASSERT(InLength <= std::numeric_limits<uInt>::max());
+
 		// Check usage
 		if(mStream.avail_in != 0)
 		{
@@ -97,7 +99,7 @@
 		
 		// Store info
 		mStream.next_in = (unsigned char *)pInBuffer;
-		mStream.avail_in = InLength;
+		mStream.avail_in = static_cast<uInt>(InLength);
 	}
 	
 	// --------------------------------------------------------------------------
@@ -121,17 +123,19 @@
 	//		Created: 5/12/03
 	//
 	// --------------------------------------------------------------------------
-	int Output(void *pOutBuffer, int OutLength, bool SyncFlush = false)
+	size_t Output(void *pOutBuffer, size_t OutLength, bool SyncFlush = false)
 	{
 		// need more input?
 		if(mStream.avail_in == 0 && mFlush != Z_FINISH && !SyncFlush)
 		{
 			return 0;
 		}
+
+		ASSERT(OutLength <= std::numeric_limits<uInt>::max());
 	
 		// Buffers
 		mStream.next_out = (unsigned char *)pOutBuffer;
-		mStream.avail_out = OutLength;
+		mStream.avail_out = static_cast<uInt>(OutLength);
 		
 		// Call one of the functions
 		int flush = mFlush;
@@ -188,7 +192,7 @@
 Integer Compress_MaxSizeForCompressedData(Integer InLen)
 {
 	// Conservative rendition of the info found here: http://www.gzip.org/zlib/zlib_tech.html
-	int blocks = (InLen + 32*1024 - 1) / (32*1024);
+	Integer blocks = (InLen + 32*1024 - 1) / (32*1024);
 	return InLen + (blocks * 6) + 8;
 }
 

Modified: box/invisnet/vs2010/0.11/lib/compress/CompressStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/compress/CompressStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/compress/CompressStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -136,7 +136,7 @@
 //		Created: 27/5/04
 //
 // --------------------------------------------------------------------------
-int CompressStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t CompressStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	USE_READ_COMPRESSOR
 	if(pDecompress == 0)
@@ -155,7 +155,7 @@
 	}
 
 	// Read data into the buffer -- read as much as possible in one go
-	int s = mpStream->Read(pbuf, BUFFER_SIZE, Timeout);
+	size_t s = mpStream->Read(pbuf, BUFFER_SIZE, Timeout);
 	if(s == 0)
 	{
 		return 0;
@@ -177,7 +177,7 @@
 //		Created: 27/5/04
 //
 // --------------------------------------------------------------------------
-void CompressStream::Write(const void *pBuffer, int NBytes)
+void CompressStream::Write(const void *pBuffer, size_t NBytes)
 {
 	USE_WRITE_COMPRESSOR
 	if(pCompress == 0)
@@ -262,7 +262,7 @@
 	USE_WRITE_COMPRESSOR
 	if(pCompress == 0) {THROW_EXCEPTION(CompressException, Internal)}
 	
-	int s = 0;
+	size_t s = 0;
 	do
 	{
 		s = pCompress->Output(mpBuffer, BUFFER_SIZE, SyncFlush);

Modified: box/invisnet/vs2010/0.11/lib/compress/CompressStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/compress/CompressStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/compress/CompressStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -32,8 +32,8 @@
 	CompressStream &operator=(const CompressStream &);
 public:
 
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual void WriteAllBuffered();
 	virtual void Close();
 	virtual bool StreamDataLeft();

Modified: box/invisnet/vs2010/0.11/lib/crypto/CipherContext.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/CipherContext.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/CipherContext.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -193,7 +193,7 @@
 //		Created: 1/12/03
 //
 // --------------------------------------------------------------------------
-int CipherContext::Transform(void *pOutBuffer, int OutLength, const void *pInBuffer, int InLength)
+size_t CipherContext::Transform(void *pOutBuffer, size_t OutLength, const void *pInBuffer, size_t InLength)
 {
 	if(!mInitialised)
 	{
@@ -206,7 +206,8 @@
 	}
 
 	// Check parameters
-	if(pOutBuffer == 0 || OutLength < 0 || (pInBuffer != 0 && InLength <= 0) || (pInBuffer == 0 && InLength != 0))
+	if(pOutBuffer == NULL || (pInBuffer != NULL && InLength == 0) || (pInBuffer == NULL && InLength != 0)
+		|| OutLength > INT_MAX || InLength > INT_MAX)
 	{
 		THROW_EXCEPTION(CipherException, BadArguments)
 	}
@@ -224,8 +225,8 @@
 	}
 	
 	// Do the transform
-	int outLength = OutLength;
-	if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, InLength) != 1)
+	int outLength = static_cast<int>(OutLength);
+	if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, static_cast<int>(InLength)) != 1)
 	{
 		THROW_EXCEPTION(CipherException, EVPUpdateFailure)
 	}
@@ -246,7 +247,7 @@
 //		Created: 1/12/03
 //
 // --------------------------------------------------------------------------
-int CipherContext::Final(void *pOutBuffer, int OutLength)
+size_t CipherContext::Final(void *pOutBuffer, size_t OutLength)
 {
 	if(!mInitialised)
 	{
@@ -259,19 +260,19 @@
 	}
 
 	// Check parameters
-	if(pOutBuffer == 0 || OutLength < 0)
+	if(pOutBuffer == NULL || OutLength > INT_MAX)
 	{
 		THROW_EXCEPTION(CipherException, BadArguments)
 	}
 
 	// Check output buffer size
-	if(OutLength < (2 * EVP_CIPHER_CTX_block_size(&ctx)))
+	int outLength = static_cast<int>(OutLength);
+	if(outLength < (2 * EVP_CIPHER_CTX_block_size(&ctx)))
 	{
 		THROW_EXCEPTION(CipherException, OutputBufferTooSmall);
 	}
 	
 	// Do the transform
-	int outLength = OutLength;
 #ifndef HAVE_OLD_SSL
 	if(EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outLength) != 1)
 	{
@@ -373,7 +374,7 @@
 //		Created: 1/12/03
 //
 // --------------------------------------------------------------------------
-int CipherContext::InSizeForOutBufferSize(int OutLength)
+size_t CipherContext::InSizeForOutBufferSize(size_t OutLength)
 {
 	if(!mInitialised)
 	{
@@ -394,7 +395,7 @@
 //		Created: 3/12/03
 //
 // --------------------------------------------------------------------------
-int CipherContext::MaxOutSizeForInBufferSize(int InLength)
+size_t CipherContext::MaxOutSizeForInBufferSize(size_t InLength)
 {
 	if(!mInitialised)
 	{
@@ -415,13 +416,18 @@
 //		Created: 1/12/03
 //
 // --------------------------------------------------------------------------
-int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *pInBuffer, int InLength)
+size_t CipherContext::TransformBlock(void *pOutBuffer, size_t OutLength, const void *pInBuffer, size_t InLength)
 {
 	if(!mInitialised)
 	{
 		THROW_EXCEPTION(CipherException, NotInitialised)
 	}
-	
+
+	if(OutLength > INT_MAX || InLength > INT_MAX)
+	{
+		THROW_EXCEPTION(CipherException, BadArguments)
+	}
+
 	// Warn if in a transformation
 	if(mWithinTransform)
 	{
@@ -454,13 +460,13 @@
 	try
 	{
 		// Update
-		outLength = OutLength;
-		if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, InLength) != 1)
+		outLength = static_cast<int>(OutLength);
+		if(EVP_CipherUpdate(&ctx, (unsigned char*)pOutBuffer, &outLength, (unsigned char*)pInBuffer, static_cast<int>(InLength)) != 1)
 		{
 			THROW_EXCEPTION(CipherException, EVPUpdateFailure)
 		}
 		// Finalise
-		int outLength2 = OutLength - outLength;
+		int outLength2 = static_cast<int>(OutLength - outLength);
 #ifndef HAVE_OLD_SSL
 		if(EVP_CipherFinal_ex(&ctx, ((unsigned char*)pOutBuffer) + outLength, &outLength2) != 1)
 		{
@@ -474,7 +480,7 @@
 	catch(...)
 	{
 		// Finalise the context, so definately ready for the next caller
-		int outs = OutLength;
+		int outs = static_cast<int>(OutLength);
 #ifndef HAVE_OLD_SSL
 		EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outs);
 #else

Modified: box/invisnet/vs2010/0.11/lib/crypto/CipherContext.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/CipherContext.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/CipherContext.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -47,12 +47,12 @@
 	void Reset();
 	
 	void Begin();
-	int Transform(void *pOutBuffer, int OutLength, const void *pInBuffer, int InLength);
-	int Final(void *pOutBuffer, int OutLength);
-	int InSizeForOutBufferSize(int OutLength);
-	int MaxOutSizeForInBufferSize(int InLength);
+	size_t Transform(void *pOutBuffer, size_t OutLength, const void *pInBuffer, size_t InLength);
+	size_t Final(void *pOutBuffer, size_t OutLength);
+	size_t InSizeForOutBufferSize(size_t OutLength);
+	size_t MaxOutSizeForInBufferSize(size_t InLength);
 	
-	int TransformBlock(void *pOutBuffer, int OutLength, const void *pInBuffer, int InLength);
+	size_t TransformBlock(void *pOutBuffer, size_t OutLength, const void *pInBuffer, size_t InLength);
 
 	bool IsInitialised() {return mInitialised;}
 	

Modified: box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -33,7 +33,7 @@
 	MD5_Update(&md5, rString.c_str(), rString.size());
 }
 
-void MD5Digest::Add(const void *pData, int Length)
+void MD5Digest::Add(const void *pData, size_t Length)
 {
 	MD5_Update(&md5, pData, Length);
 }
@@ -58,7 +58,7 @@
 	return r;
 }
 
-int MD5Digest::CopyDigestTo(uint8_t *to)
+size_t MD5Digest::CopyDigestTo(uint8_t *to)
 {
 	for(int l = 0; l < MD5_DIGEST_LENGTH; ++l)
 	{

Modified: box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/MD5Digest.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -28,12 +28,12 @@
 	virtual ~MD5Digest();
 
 	void Add(const std::string &rString);
-	void Add(const void *pData, int Length);
+	void Add(const void *pData, size_t Length);
 
 	void Finish();
 
 	std::string DigestAsString();
-	uint8_t *DigestAsData(int *pLength = 0)
+	uint8_t *DigestAsData(size_t *pLength = 0)
 	{
 		if(pLength) *pLength = sizeof(mDigest);
 		return mDigest;
@@ -44,7 +44,7 @@
 		DigestLength = MD5_DIGEST_LENGTH
 	};
 
-	int CopyDigestTo(uint8_t *to);
+	size_t CopyDigestTo(uint8_t *to);
 
 	bool DigestMatches(uint8_t *pCompareWith) const;
 

Modified: box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -20,15 +20,15 @@
 //		Created: 6/12/03
 //
 // --------------------------------------------------------------------------
-RollingChecksum::RollingChecksum(const void * const data, const unsigned int Length)
+RollingChecksum::RollingChecksum(const void * const data, const size_t Length)
 	: a(0),
 	  b(0)
 {
 	const uint8_t *block = (const uint8_t *)data;
-	for(unsigned int x = Length; x >= 1; --x)
+	for(size_t x = Length; x >= 1; --x)
 	{
 		a += (*block);
-		b += x * (*block);
+		b = static_cast<uint16_t>(b + x * (*block));
 		
 		++block;
 	}
@@ -43,7 +43,7 @@
 //		Created: 7/14/05
 //
 // --------------------------------------------------------------------------
-void RollingChecksum::RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const unsigned int Length, const unsigned int Skip)
+void RollingChecksum::RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const size_t Length, const size_t Skip)
 {
 	// IMPLEMENTATION NOTE: Everything is implicitly mod 2^16 -- uint16_t's will overflow nicely.
 	unsigned int i;
@@ -58,5 +58,5 @@
 		b += a;
 	}
 
-	b -= Length * sumBegin;
+	b = static_cast<uint16_t>(b - Length * sumBegin);
 }

Modified: box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/crypto/RollingChecksum.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -24,7 +24,7 @@
 class RollingChecksum
 {
 public:
-	RollingChecksum(const void * const data, const unsigned int Length);
+	RollingChecksum(const void * const data, const size_t Length);
 
 	// --------------------------------------------------------------------------
 	//
@@ -35,12 +35,12 @@
 	//		Created: 6/12/03
 	//
 	// --------------------------------------------------------------------------
-	inline void RollForward(const uint8_t StartOfThisBlock, const uint8_t LastOfNextBlock, const unsigned int Length)
+	inline void RollForward(const uint8_t StartOfThisBlock, const uint8_t LastOfNextBlock, const size_t Length)
 	{
 		// IMPLEMENTATION NOTE: Everything is implicitly mod 2^16 -- uint16_t's will overflow nicely.
 		a -= StartOfThisBlock;
 		a += LastOfNextBlock;
-		b -= Length * StartOfThisBlock;
+		b -= static_cast<uint16_t>(Length * StartOfThisBlock);
 		b += a;
 	}
 
@@ -53,7 +53,7 @@
 	//		Created: 7/14/05
 	//
 	// --------------------------------------------------------------------------
-	void RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const unsigned int Length, const unsigned int Skip);
+	void RollForwardSeveral(const uint8_t * const StartOfThisBlock, const uint8_t * const LastOfNextBlock, const size_t Length, const size_t Skip);
 
 	// --------------------------------------------------------------------------
 	//

Modified: box/invisnet/vs2010/0.11/lib/server/Protocol.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/Protocol.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/Protocol.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -50,9 +50,9 @@
 	  mTimeout(PROTOCOL_DEFAULT_TIMEOUT),
 	  mpBuffer(0),
 	  mBufferSize(0),
-	  mReadOffset(-1),
-	  mWriteOffset(-1),
-	  mValidDataSize(-1),
+	  mReadOffset(SIZE_MAX),
+	  mWriteOffset(SIZE_MAX),
+	  mValidDataSize(SIZE_MAX),
 	  mLastErrorType(NoError),
 	  mLastErrorSubType(NoError)
 {
@@ -137,11 +137,11 @@
 	PW_Handshake hsReceive;
 	::memset(&hsReceive, 0, sizeof(hsReceive));
 	char *readInto = (char*)&hsReceive;
-	int bytesToRead = sizeof(hsReceive);
+	size_t bytesToRead = sizeof(hsReceive);
 	while(bytesToRead > 0)
 	{
 		// Get some data from the stream
-		int bytesRead = mrStream.Read(readInto, bytesToRead, mTimeout);
+		size_t bytesRead = mrStream.Read(readInto, bytesToRead, mTimeout);
 		if(bytesRead == 0)
 		{
 			THROW_EXCEPTION(ConnectionException, Conn_Protocol_Timeout)
@@ -173,7 +173,7 @@
 void Protocol::CheckAndReadHdr(void *hdr)
 {
 	// Check usage
-	if(mValidDataSize != -1 || mWriteOffset != -1 || mReadOffset != -1)
+	if(mValidDataSize != SIZE_MAX || mWriteOffset != SIZE_MAX || mReadOffset != SIZE_MAX)
 	{
 		THROW_EXCEPTION(ServerException, Protocol_BadUsage)
 	}
@@ -243,8 +243,8 @@
 	catch(...)
 	{
 		// Make sure state is reset!
-		mValidDataSize = -1;
-		mReadOffset = -1;
+		mValidDataSize = SIZE_MAX;
+		mReadOffset = SIZE_MAX;
 		throw;
 	}
 	
@@ -252,8 +252,8 @@
 	bool dataLeftOver = (mValidDataSize != mReadOffset);
 	
 	// Unset read state, so future read calls don't fail
-	mValidDataSize = -1;
-	mReadOffset = -1;
+	mValidDataSize = SIZE_MAX;
+	mReadOffset = SIZE_MAX;
 	
 	// Exception if not all the data was consumed
 	if(dataLeftOver)
@@ -275,7 +275,7 @@
 void Protocol::Send(const ProtocolObject &rObject)
 {
 	// Check usage
-	if(mValidDataSize != -1 || mWriteOffset != -1 || mReadOffset != -1)
+	if(mValidDataSize != SIZE_MAX || mWriteOffset != SIZE_MAX || mReadOffset != SIZE_MAX)
 	{
 		THROW_EXCEPTION(ServerException, Protocol_BadUsage)
 	}
@@ -288,7 +288,7 @@
 
 	// Make sure there's a little bit of space allocated
 	EnsureBufferAllocated(((sizeof(PW_ObjectHeader) + PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK - 1) / PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK) * PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK);
-	ASSERT(mBufferSize >= (int)sizeof(PW_ObjectHeader));
+	ASSERT(mBufferSize >= sizeof(PW_ObjectHeader));
 	
 	// Setup for write operation
 	mValidDataSize = 0;		// Not used, but must not be -1
@@ -301,17 +301,18 @@
 	catch(...)
 	{
 		// Make sure state is reset!
-		mValidDataSize = -1;
-		mWriteOffset = -1;
+		mValidDataSize = SIZE_MAX;
+		mWriteOffset = SIZE_MAX;
 		throw;
 	}
 
 	// How big?
-	int writtenSize = mWriteOffset;
+	ASSERT(mWriteOffset <= UINT_MAX);
+	u_int32_t writtenSize = static_cast<u_int32_t>(mWriteOffset);
 
 	// Reset write state
-	mValidDataSize = -1;
-	mWriteOffset = -1;	
+	mValidDataSize = SIZE_MAX;
+	mWriteOffset = SIZE_MAX;
 	
 	// Make header in the existing block
 	PW_ObjectHeader *pobjHeader = (PW_ObjectHeader*)(mpBuffer);
@@ -331,7 +332,7 @@
 //		Created: 2003/08/19
 //
 // --------------------------------------------------------------------------
-void Protocol::EnsureBufferAllocated(int Size)
+void Protocol::EnsureBufferAllocated(size_t Size)
 {
 	if(mpBuffer != 0 && mBufferSize >= Size)
 	{
@@ -365,13 +366,13 @@
 
 
 #define READ_START_CHECK														\
-	if(mValidDataSize == -1 || mWriteOffset != -1 || mReadOffset == -1)			\
+	if(mValidDataSize == SIZE_MAX || mWriteOffset != SIZE_MAX || mReadOffset == SIZE_MAX)			\
 	{																			\
 		THROW_EXCEPTION(ServerException, Protocol_BadUsage)						\
 	}
 
 #define READ_CHECK_BYTES_AVAILABLE(bytesRequired)								\
-	if((mReadOffset + (int)(bytesRequired)) > mValidDataSize)					\
+	if(mReadOffset + bytesRequired > mValidDataSize)					\
 	{																			\
 		THROW_EXCEPTION(ConnectionException, Conn_Protocol_BadCommandRecieved)	\
 	}
@@ -384,7 +385,7 @@
 //		Created: 2003/08/19
 //
 // --------------------------------------------------------------------------
-void Protocol::Read(void *Buffer, int Size)
+void Protocol::Read(void *Buffer, size_t Size)
 {
 	READ_START_CHECK
 	READ_CHECK_BYTES_AVAILABLE(Size)
@@ -402,7 +403,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-void Protocol::Read(std::string &rOut, int Size)
+void Protocol::Read(std::string &rOut, size_t Size)
 {
 	READ_START_CHECK
 	READ_CHECK_BYTES_AVAILABLE(Size)
@@ -518,7 +519,7 @@
 
 
 #define WRITE_START_CHECK														\
-	if(mValidDataSize == -1 || mWriteOffset == -1 || mReadOffset != -1)			\
+	if(mValidDataSize == SIZE_MAX || mWriteOffset == SIZE_MAX || mReadOffset != SIZE_MAX)			\
 	{																			\
 		THROW_EXCEPTION(ServerException, Protocol_BadUsage)						\
 	}
@@ -538,7 +539,7 @@
 //		Created: 2003/08/19
 //
 // --------------------------------------------------------------------------
-void Protocol::Write(const void *Buffer, int Size)
+void Protocol::Write(const void *Buffer, size_t Size)
 {
 	WRITE_START_CHECK
 	WRITE_ENSURE_BYTES_AVAILABLE(Size)
@@ -695,7 +696,7 @@
 void Protocol::SendStream(IOStream &rStream)
 {
 	// Check usage
-	if(mValidDataSize != -1 || mWriteOffset != -1 || mReadOffset != -1)
+	if(mValidDataSize != SIZE_MAX || mWriteOffset != SIZE_MAX || mReadOffset != SIZE_MAX)
 	{
 		THROW_EXCEPTION(ServerException, Protocol_BadUsage)
 	}
@@ -721,7 +722,7 @@
 	
 	// Make header
 	PW_ObjectHeader objHeader;
-	objHeader.mObjSize = htonl(uncertainSize?(ProtocolStream_SizeUncertain):streamSize);
+	objHeader.mObjSize = htonl(static_cast<uint32_t>(uncertainSize?(ProtocolStream_SizeUncertain):streamSize));
 	objHeader.mObjType = htonl(SPECIAL_STREAM_OBJECT_TYPE);
 
 	// Write header
@@ -741,7 +742,7 @@
 		
 		try
 		{
-			int bytesInBlock = 0;
+			size_t bytesInBlock = 0;
 			while(rStream.StreamDataLeft())
 			{
 				// Read some of it
@@ -794,7 +795,7 @@
 //		Created: 5/12/03
 //
 // --------------------------------------------------------------------------
-int Protocol::SendStreamSendBlock(uint8_t *Block, int BytesInBlock)
+size_t Protocol::SendStreamSendBlock(uint8_t *Block, size_t BytesInBlock)
 {
 	// Quick sanity check
 	if(BytesInBlock == 0)
@@ -805,7 +806,7 @@
 	
 	// Work out the header byte
 	uint8_t header = 0;
-	int writeSize = 0;
+	size_t writeSize = 0;
 	if(BytesInBlock >= (64*1024))
 	{
 		header = ProtocolStreamHeader_SizeIs64k;
@@ -852,7 +853,7 @@
 //		Created: 2003/10/27
 //
 // --------------------------------------------------------------------------
-void Protocol::InformStreamReceiving(u_int32_t Size)
+void Protocol::InformStreamReceiving(IOStream::pos_type Size)
 {
 	// Do nothing
 }
@@ -865,7 +866,7 @@
 //		Created: 2003/10/27
 //
 // --------------------------------------------------------------------------
-void Protocol::InformStreamSending(u_int32_t Size)
+void Protocol::InformStreamSending(IOStream::pos_type Size)
 {
 	// Do nothing
 }

Modified: box/invisnet/vs2010/0.11/lib/server/Protocol.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/Protocol.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/Protocol.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -89,8 +89,8 @@
 	void SetMaxObjectSize(unsigned int NewMaxObjSize) {mMaxObjectSize = NewMaxObjSize;}
 
 	// For ProtocolObject derived classes
-	void Read(void *Buffer, int Size);
-	void Read(std::string &rOut, int Size);
+	void Read(void *Buffer, size_t Size);
+	void Read(std::string &rOut, size_t Size);
 	void Read(int64_t &rOut);
 	void Read(int32_t &rOut);
 	void Read(int16_t &rOut);
@@ -124,7 +124,7 @@
 		}
 	}
 	
-	void Write(const void *Buffer, int Size);
+	void Write(const void *Buffer, size_t Size);
 	void Write(int64_t Value);
 	void Write(int32_t Value);
 	void Write(int16_t Value);
@@ -177,12 +177,12 @@
 	void CheckAndReadHdr(void *hdr);	// don't use type here to avoid dependency
 	
 	// Will be used for logging
-	virtual void InformStreamReceiving(u_int32_t Size);
-	virtual void InformStreamSending(u_int32_t Size);
+	virtual void InformStreamReceiving(IOStream::pos_type Size);
+	virtual void InformStreamSending(IOStream::pos_type Size);
 	
 private:
-	void EnsureBufferAllocated(int Size);
-	int SendStreamSendBlock(uint8_t *Block, int BytesInBlock);
+	void EnsureBufferAllocated(size_t Size);
+	size_t SendStreamSendBlock(uint8_t *Block, size_t BytesInBlock);
 
 private:
 	IOStream &mrStream;
@@ -190,10 +190,10 @@
 	unsigned int mMaxObjectSize;
 	int mTimeout;
 	char *mpBuffer;
-	int mBufferSize;
-	int mReadOffset;
-	int mWriteOffset;
-	int mValidDataSize;
+	size_t mBufferSize;
+	size_t mReadOffset;
+	size_t mWriteOffset;
+	size_t mValidDataSize;
 	int mLastErrorType;
 	int mLastErrorSubType;
 };

Modified: box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -54,7 +54,7 @@
 //		Created: 2003/12/05
 //
 // --------------------------------------------------------------------------
-int ProtocolUncertainStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t ProtocolUncertainStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// Finished?
 	if(mFinished)
@@ -62,7 +62,7 @@
 		return 0;
 	}
 	
-	int read = 0;
+	size_t read = 0;
 	while(read < NBytes)
 	{
 		// Anything we can get from the current block?
@@ -70,7 +70,7 @@
 		if(mBytesLeftInCurrentBlock > 0)
 		{
 			// Yes, let's use some of these up
-			int toRead = (NBytes - read);
+			size_t toRead = (NBytes - read);
 			if(toRead > mBytesLeftInCurrentBlock)
 			{
 				// Adjust downwards to only read stuff out of the current block
@@ -80,7 +80,7 @@
 			BOX_TRACE("Reading " << toRead << " bytes from stream");
 	
 			// Read it
-			int r = mrSource.Read(((uint8_t*)pBuffer) + read, toRead, Timeout);
+			size_t r = mrSource.Read(((uint8_t*)pBuffer) + read, toRead, Timeout);
 			// Give up now if it didn't return anything
 			if(r == 0)
 			{
@@ -172,7 +172,7 @@
 //		Created: 2003/12/05
 //
 // --------------------------------------------------------------------------
-void ProtocolUncertainStream::Write(const void *pBuffer, int NBytes)
+void ProtocolUncertainStream::Write(const void *pBuffer, size_t NBytes)
 {
 	THROW_EXCEPTION(ServerException, CantWriteToProtocolUncertainStream)
 }

Modified: box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/ProtocolUncertainStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -31,15 +31,15 @@
 	ProtocolUncertainStream(const ProtocolUncertainStream &);
 	
 public:
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type BytesLeftToRead();
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 
 private:
 	IOStream &mrSource;
-	int mBytesLeftInCurrentBlock;
+	size_t mBytesLeftInCurrentBlock;
 	bool mFinished;
 };
 

Modified: box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -294,10 +294,13 @@
 //		Created: 2003/08/06
 //
 // --------------------------------------------------------------------------
-int SocketStreamTLS::Read(void *pBuffer, int NBytes, int Timeout)
+size_t SocketStreamTLS::Read(void *pBuffer, size_t NBytes_, int Timeout)
 {
 	if(!mpSSL) {THROW_EXCEPTION(ServerException, TLSNoSSLObject)}
 
+	ASSERT(NBytes_ < INT_MAX);
+	int NBytes = static_cast<int>(NBytes_);
+
 	// Make sure zero byte reads work as expected
 	if(NBytes == 0)
 	{
@@ -350,9 +353,12 @@
 //		Created: 2003/08/06
 //
 // --------------------------------------------------------------------------
-void SocketStreamTLS::Write(const void *pBuffer, int NBytes)
+void SocketStreamTLS::Write(const void *pBuffer, size_t NBytes_)
 {
 	if(!mpSSL) {THROW_EXCEPTION(ServerException, TLSNoSSLObject)}
+
+	ASSERT(NBytes_ < INT_MAX);
+	int NBytes = static_cast<int>(NBytes_);
 	
 	// Make sure zero byte writes work as expected
 	if(NBytes == 0)

Modified: box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/SocketStreamTLS.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -42,8 +42,8 @@
 		const std::string& rName, int Port = 0);
 	void Handshake(const TLSContext &rContext, bool IsServer = false);
 	
-	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual size_t Read(void *pBuffer, size_t NBytes, int Timeout = IOStream::TimeOutInfinite);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual void Close();
 	virtual void Shutdown(bool Read = true, bool Write = true);
 

Modified: box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.cpp	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.cpp	2010-10-17 21:31:28 UTC (rev 2792)
@@ -247,7 +247,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout)
+size_t WinNamedPipeStream::Read(void *pBuffer, size_t NBytes, int Timeout)
 {
 	// TODO no support for timeouts yet
 	if (!mIsServer && Timeout != IOStream::TimeOutInfinite)
@@ -445,7 +445,7 @@
 //		Created: 2003/07/31
 //
 // --------------------------------------------------------------------------
-void WinNamedPipeStream::Write(const void *pBuffer, int NBytes)
+void WinNamedPipeStream::Write(const void *pBuffer, size_t NBytes)
 {
 	if (mSocketHandle == INVALID_HANDLE_VALUE || !mIsConnected) 
 	{

Modified: box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.h	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/WinNamedPipeStream.h	2010-10-17 21:31:28 UTC (rev 2792)
@@ -34,9 +34,9 @@
 	void Connect(const std::string& rName);
 
 	// both sides
-	virtual int Read(void *pBuffer, int NBytes, 
+	virtual size_t Read(void *pBuffer, size_t NBytes, 
 		int Timeout = IOStream::TimeOutInfinite);
-	virtual void Write(const void *pBuffer, int NBytes);
+	virtual void Write(const void *pBuffer, size_t NBytes);
 	virtual void WriteAllBuffered();
 	virtual void Close();
 	virtual bool StreamDataLeft();

Modified: box/invisnet/vs2010/0.11/lib/server/makeprotocol.pl.in
===================================================================
--- box/invisnet/vs2010/0.11/lib/server/makeprotocol.pl.in	2010-10-16 17:31:19 UTC (rev 2791)
+++ box/invisnet/vs2010/0.11/lib/server/makeprotocol.pl.in	2010-10-17 21:31:28 UTC (rev 2792)
@@ -625,8 +625,8 @@
 if($implement_filelog || $implement_syslog)
 {
 	print H <<__E;
-	virtual void InformStreamReceiving(u_int32_t Size);
-	virtual void InformStreamSending(u_int32_t Size);
+	virtual void InformStreamReceiving(IOStream::pos_type Size);
+	virtual void InformStreamSending(IOStream::pos_type Size);
 __E
 }
 
@@ -864,11 +864,11 @@
 
 	print CPP <<__E;
 
-void ${prefix}InformStreamReceiving(u_int32_t Size)
+void ${prefix}InformStreamReceiving(IOStream::pos_type Size)
 {
 $fR}
 
-void ${prefix}InformStreamSending(u_int32_t Size)
+void ${prefix}InformStreamSending(IOStream::pos_type Size)
 {
 $fS}
 




More information about the Boxbackup-commit mailing list