Blame SOURCES/tigervnc-CVE-2019-15694.patch

aeab07
From 0943c006c7d900dfc0281639e992791d6c567438 Mon Sep 17 00:00:00 2001
aeab07
From: Pierre Ossman <ossman@cendio.se>
aeab07
Date: Mon, 23 Sep 2019 11:00:17 +0200
aeab07
Subject: [PATCH] Use size_t for lengths in stream objects
aeab07
aeab07
Provides safety against them accidentally becoming negative because
aeab07
of bugs in the calculations.
aeab07
aeab07
Also does the same to CharArray and friends as they were strongly
aeab07
connection to the stream objects.
aeab07
---
aeab07
 common/rdr/FdInStream.cxx    | 20 ++++++++++----------
aeab07
 common/rdr/FdInStream.h      | 17 +++++++++--------
aeab07
 common/rdr/FdOutStream.cxx   | 20 ++++++++++----------
aeab07
 common/rdr/FdOutStream.h     | 12 ++++++------
aeab07
 common/rdr/FileInStream.cxx  |  8 ++++----
aeab07
 common/rdr/FileInStream.h    |  4 ++--
aeab07
 common/rdr/HexInStream.cxx   | 20 ++++++++++----------
aeab07
 common/rdr/HexInStream.h     | 12 ++++++------
aeab07
 common/rdr/HexOutStream.cxx  | 20 ++++++++++----------
aeab07
 common/rdr/HexOutStream.h    | 12 ++++++------
aeab07
 common/rdr/InStream.h        | 16 ++++++++--------
aeab07
 common/rdr/MemInStream.h     |  8 ++++----
aeab07
 common/rdr/MemOutStream.h    | 12 ++++++------
aeab07
 common/rdr/OutStream.h       | 20 ++++++++++----------
aeab07
 common/rdr/RandomStream.cxx  | 14 +++++++-------
aeab07
 common/rdr/RandomStream.h    |  6 +++---
aeab07
 common/rdr/TLSInStream.cxx   | 10 +++++-----
aeab07
 common/rdr/TLSInStream.h     | 10 +++++-----
aeab07
 common/rdr/TLSOutStream.cxx  | 10 +++++-----
aeab07
 common/rdr/TLSOutStream.h    | 10 +++++-----
aeab07
 common/rdr/ZlibInStream.cxx  | 16 ++++++++--------
aeab07
 common/rdr/ZlibInStream.h    | 14 +++++++-------
aeab07
 common/rdr/ZlibOutStream.cxx | 10 +++++-----
aeab07
 common/rdr/ZlibOutStream.h   | 10 +++++-----
aeab07
 common/rfb/Configuration.cxx |  6 +++---
aeab07
 common/rfb/Configuration.h   | 13 +++++++------
aeab07
 common/rfb/Password.cxx      |  6 +++---
aeab07
 common/rfb/Password.h        |  6 +++---
aeab07
 common/rfb/util.h            |  2 +-
aeab07
 tests/perf/encperf.cxx       | 10 +++++-----
aeab07
 win/rfb_win32/Registry.cxx   |  6 +++---
aeab07
 win/rfb_win32/Registry.h     |  6 +++---
aeab07
 32 files changed, 184 insertions(+), 182 deletions(-)
aeab07
aeab07
diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx
aeab07
index 011ebf4..789cbec 100644
aeab07
--- a/common/rdr/FdInStream.cxx
aeab07
+++ b/common/rdr/FdInStream.cxx
aeab07
@@ -56,7 +56,7 @@ using namespace rdr;
aeab07
 enum { DEFAULT_BUF_SIZE = 8192,
aeab07
        MIN_BULK_SIZE = 1024 };
aeab07
 
aeab07
-FdInStream::FdInStream(int fd_, int timeoutms_, int bufSize_,
aeab07
+FdInStream::FdInStream(int fd_, int timeoutms_, size_t bufSize_,
aeab07
                        bool closeWhenDone_)
aeab07
   : fd(fd_), closeWhenDone(closeWhenDone_),
aeab07
     timeoutms(timeoutms_), blockCallback(0),
aeab07
@@ -67,7 +67,7 @@ FdInStream::FdInStream(int fd_, int timeoutms_, int bufSize_,
aeab07
 }
aeab07
 
aeab07
 FdInStream::FdInStream(int fd_, FdInStreamBlockCallback* blockCallback_,
aeab07
-                       int bufSize_)
aeab07
+                       size_t bufSize_)
aeab07
   : fd(fd_), timeoutms(0), blockCallback(blockCallback_),
aeab07
     timing(false), timeWaitedIn100us(5), timedKbits(0),
aeab07
     bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
aeab07
@@ -92,12 +92,12 @@ void FdInStream::setBlockCallback(FdInStreamBlockCallback* blockCallback_)
aeab07
   timeoutms = 0;
aeab07
 }
aeab07
 
aeab07
-int FdInStream::pos()
aeab07
+size_t FdInStream::pos()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
 
aeab07
-void FdInStream::readBytes(void* data, int length)
aeab07
+void FdInStream::readBytes(void* data, size_t length)
aeab07
 {
aeab07
   if (length < MIN_BULK_SIZE) {
aeab07
     InStream::readBytes(data, length);
aeab07
@@ -106,7 +106,7 @@ void FdInStream::readBytes(void* data, int length)
aeab07
 
aeab07
   U8* dataPtr = (U8*)data;
aeab07
 
aeab07
-  int n = end - ptr;
aeab07
+  size_t n = end - ptr;
aeab07
   if (n > length) n = length;
aeab07
 
aeab07
   memcpy(dataPtr, ptr, n);
aeab07
@@ -123,7 +123,7 @@ void FdInStream::readBytes(void* data, int length)
aeab07
 }
aeab07
 
aeab07
 
aeab07
-int FdInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
+size_t FdInStream::overrun(size_t itemSize, size_t nItems, bool wait)
aeab07
 {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("FdInStream overrun: max itemSize exceeded");
aeab07
@@ -135,7 +135,7 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
   end -= ptr - start;
aeab07
   ptr = start;
aeab07
 
aeab07
-  int bytes_to_read;
aeab07
+  size_t bytes_to_read;
aeab07
   while (end < start + itemSize) {
aeab07
     bytes_to_read = start + bufSize - end;
aeab07
     if (!timing) {
aeab07
@@ -147,12 +147,12 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
       // bytes is ineffecient.
aeab07
       bytes_to_read = vncmin(bytes_to_read, vncmax(itemSize*nItems, 8));
aeab07
     }
aeab07
-    int n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait);
aeab07
+    size_t n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait);
aeab07
     if (n == 0) return 0;
aeab07
     end += n;
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
@@ -171,7 +171,7 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
 // returning EINTR.
aeab07
 //
aeab07
 
aeab07
-int FdInStream::readWithTimeoutOrCallback(void* buf, int len, bool wait)
aeab07
+size_t FdInStream::readWithTimeoutOrCallback(void* buf, size_t len, bool wait)
aeab07
 {
aeab07
   struct timeval before, after;
aeab07
   if (timing)
aeab07
diff --git a/common/rdr/FdInStream.h b/common/rdr/FdInStream.h
aeab07
index b4c8765..d99ad3c 100644
aeab07
--- a/common/rdr/FdInStream.h
aeab07
+++ b/common/rdr/FdInStream.h
aeab07
@@ -37,16 +37,17 @@ namespace rdr {
aeab07
 
aeab07
   public:
aeab07
 
aeab07
-    FdInStream(int fd, int timeoutms=-1, int bufSize=0,
aeab07
+    FdInStream(int fd, int timeoutms=-1, size_t bufSize=0,
aeab07
                bool closeWhenDone_=false);
aeab07
-    FdInStream(int fd, FdInStreamBlockCallback* blockCallback, int bufSize=0);
aeab07
+    FdInStream(int fd, FdInStreamBlockCallback* blockCallback,
aeab07
+               size_t bufSize=0);
aeab07
     virtual ~FdInStream();
aeab07
 
aeab07
     void setTimeout(int timeoutms);
aeab07
     void setBlockCallback(FdInStreamBlockCallback* blockCallback);
aeab07
     int getFd() { return fd; }
aeab07
-    int pos();
aeab07
-    void readBytes(void* data, int length);
aeab07
+    size_t pos();
aeab07
+    void readBytes(void* data, size_t length);
aeab07
 
aeab07
     void startTiming();
aeab07
     void stopTiming();
aeab07
@@ -54,10 +55,10 @@ namespace rdr {
aeab07
     unsigned int timeWaited() { return timeWaitedIn100us; }
aeab07
 
aeab07
   protected:
aeab07
-    int overrun(int itemSize, int nItems, bool wait);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait);
aeab07
 
aeab07
   private:
aeab07
-    int readWithTimeoutOrCallback(void* buf, int len, bool wait=true);
aeab07
+    size_t readWithTimeoutOrCallback(void* buf, size_t len, bool wait=true);
aeab07
 
aeab07
     int fd;
aeab07
     bool closeWhenDone;
aeab07
@@ -68,8 +69,8 @@ namespace rdr {
aeab07
     unsigned int timeWaitedIn100us;
aeab07
     unsigned int timedKbits;
aeab07
 
aeab07
-    int bufSize;
aeab07
-    int offset;
aeab07
+    size_t bufSize;
aeab07
+    size_t offset;
aeab07
     U8* start;
aeab07
   };
aeab07
 
aeab07
diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx
aeab07
index cf857f8..1757dc3 100644
aeab07
--- a/common/rdr/FdOutStream.cxx
aeab07
+++ b/common/rdr/FdOutStream.cxx
aeab07
@@ -51,7 +51,7 @@ using namespace rdr;
aeab07
 
aeab07
 enum { DEFAULT_BUF_SIZE = 16384 };
aeab07
 
aeab07
-FdOutStream::FdOutStream(int fd_, bool blocking_, int timeoutms_, int bufSize_)
aeab07
+FdOutStream::FdOutStream(int fd_, bool blocking_, int timeoutms_, size_t bufSize_)
aeab07
   : fd(fd_), blocking(blocking_), timeoutms(timeoutms_),
aeab07
     bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
aeab07
 {
aeab07
@@ -79,7 +79,7 @@ void FdOutStream::setBlocking(bool blocking_) {
aeab07
   blocking = blocking_;
aeab07
 }
aeab07
 
aeab07
-int FdOutStream::length()
aeab07
+size_t FdOutStream::length()
aeab07
 {
aeab07
   return offset + ptr - sentUpTo;
aeab07
 }
aeab07
@@ -97,9 +97,9 @@ unsigned FdOutStream::getIdleTime()
aeab07
 void FdOutStream::flush()
aeab07
 {
aeab07
   while (sentUpTo < ptr) {
aeab07
-    int n = writeWithTimeout((const void*) sentUpTo,
aeab07
-                             ptr - sentUpTo,
aeab07
-                             blocking? timeoutms : 0);
aeab07
+    size_t n = writeWithTimeout((const void*) sentUpTo,
aeab07
+                                ptr - sentUpTo,
aeab07
+                                blocking? timeoutms : 0);
aeab07
 
aeab07
     // Timeout?
aeab07
     if (n == 0) {
aeab07
@@ -120,7 +120,7 @@ void FdOutStream::flush()
aeab07
 }
aeab07
 
aeab07
 
aeab07
-int FdOutStream::overrun(int itemSize, int nItems)
aeab07
+size_t FdOutStream::overrun(size_t itemSize, size_t nItems)
aeab07
 {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("FdOutStream overrun: max itemSize exceeded");
aeab07
@@ -129,10 +129,10 @@ int FdOutStream::overrun(int itemSize, int nItems)
aeab07
   flush();
aeab07
 
aeab07
   // Still not enough space?
aeab07
-  if (itemSize > end - ptr) {
aeab07
+  if (itemSize > (size_t)(end - ptr)) {
aeab07
     // Can we shuffle things around?
aeab07
     // (don't do this if it gains us less than 25%)
aeab07
-    if ((sentUpTo - start > bufSize / 4) &&
aeab07
+    if (((size_t)(sentUpTo - start) > bufSize / 4) &&
aeab07
         (itemSize < bufSize - (ptr - sentUpTo))) {
aeab07
       memmove(start, sentUpTo, ptr - sentUpTo);
aeab07
       ptr = start + (ptr - sentUpTo);
aeab07
@@ -150,7 +150,7 @@ int FdOutStream::overrun(int itemSize, int nItems)
aeab07
   }
aeab07
 
aeab07
   // Can we fit all the items asked for?
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
@@ -166,7 +166,7 @@ int FdOutStream::overrun(int itemSize, int nItems)
aeab07
 // select() and send() returning EINTR.
aeab07
 //
aeab07
 
aeab07
-int FdOutStream::writeWithTimeout(const void* data, int length, int timeoutms)
aeab07
+size_t FdOutStream::writeWithTimeout(const void* data, size_t length, int timeoutms)
aeab07
 {
aeab07
   int n;
aeab07
 
aeab07
diff --git a/common/rdr/FdOutStream.h b/common/rdr/FdOutStream.h
aeab07
index b7f6cb0..ed84fdb 100644
aeab07
--- a/common/rdr/FdOutStream.h
aeab07
+++ b/common/rdr/FdOutStream.h
aeab07
@@ -34,7 +34,7 @@ namespace rdr {
aeab07
 
aeab07
   public:
aeab07
 
aeab07
-    FdOutStream(int fd, bool blocking=true, int timeoutms=-1, int bufSize=0);
aeab07
+    FdOutStream(int fd, bool blocking=true, int timeoutms=-1, size_t bufSize=0);
aeab07
     virtual ~FdOutStream();
aeab07
 
aeab07
     void setTimeout(int timeoutms);
aeab07
@@ -42,20 +42,20 @@ namespace rdr {
aeab07
     int getFd() { return fd; }
aeab07
 
aeab07
     void flush();
aeab07
-    int length();
aeab07
+    size_t length();
aeab07
 
aeab07
     int bufferUsage();
aeab07
 
aeab07
     unsigned getIdleTime();
aeab07
 
aeab07
   private:
aeab07
-    int overrun(int itemSize, int nItems);
aeab07
-    int writeWithTimeout(const void* data, int length, int timeoutms);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems);
aeab07
+    size_t writeWithTimeout(const void* data, size_t length, int timeoutms);
aeab07
     int fd;
aeab07
     bool blocking;
aeab07
     int timeoutms;
aeab07
-    int bufSize;
aeab07
-    int offset;
aeab07
+    size_t bufSize;
aeab07
+    size_t offset;
aeab07
     U8* start;
aeab07
     U8* sentUpTo;
aeab07
     struct timeval lastWrite;
aeab07
diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx
aeab07
index 3acdfd4..94f5db8 100644
aeab07
--- a/common/rdr/FileInStream.cxx
aeab07
+++ b/common/rdr/FileInStream.cxx
aeab07
@@ -48,7 +48,7 @@ void FileInStream::reset(void) {
aeab07
   ptr = end = b;
aeab07
 }
aeab07
 
aeab07
-int FileInStream::pos()
aeab07
+size_t FileInStream::pos()
aeab07
 {
aeab07
   if (!file)
aeab07
     throw Exception("File is not open");
aeab07
@@ -56,9 +56,9 @@ int FileInStream::pos()
aeab07
   return ftell(file) + ptr - b;
aeab07
 }
aeab07
 
aeab07
-int FileInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
+size_t FileInStream::overrun(size_t itemSize, size_t nItems, bool wait)
aeab07
 {
aeab07
-  if (itemSize > (int)sizeof(b))
aeab07
+  if (itemSize > sizeof(b))
aeab07
     throw Exception("FileInStream overrun: max itemSize exceeded");
aeab07
 
aeab07
   if (end - ptr != 0)
aeab07
@@ -80,7 +80,7 @@ int FileInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
     end += b + sizeof(b) - end;
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
diff --git a/common/rdr/FileInStream.h b/common/rdr/FileInStream.h
aeab07
index ace04f3..a33c765 100644
aeab07
--- a/common/rdr/FileInStream.h
aeab07
+++ b/common/rdr/FileInStream.h
aeab07
@@ -35,10 +35,10 @@ namespace rdr {
aeab07
 
aeab07
     void reset(void);
aeab07
 
aeab07
-    int pos();
aeab07
+    size_t pos();
aeab07
 
aeab07
   protected:
aeab07
-    int overrun(int itemSize, int nItems, bool wait = true);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait = true);
aeab07
 
aeab07
   private:
aeab07
     U8 b[131072];
aeab07
diff --git a/common/rdr/HexInStream.cxx b/common/rdr/HexInStream.cxx
aeab07
index 80f8a79..8f93988 100644
aeab07
--- a/common/rdr/HexInStream.cxx
aeab07
+++ b/common/rdr/HexInStream.cxx
aeab07
@@ -28,7 +28,7 @@ const int DEFAULT_BUF_LEN = 16384;
aeab07
 
aeab07
 static inline int min(int a, int b) {return a
aeab07
 
aeab07
-HexInStream::HexInStream(InStream& is, int bufSize_)
aeab07
+HexInStream::HexInStream(InStream& is, size_t bufSize_)
aeab07
 : bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_LEN), offset(0), in_stream(is)
aeab07
 {
aeab07
   ptr = end = start = new U8[bufSize];
aeab07
@@ -50,8 +50,8 @@ bool HexInStream::readHexAndShift(char c, int* v) {
aeab07
   return true;
aeab07
 }
aeab07
 
aeab07
-bool HexInStream::hexStrToBin(const char* s, char** data, int* length) {
aeab07
-  int l=strlen(s);
aeab07
+bool HexInStream::hexStrToBin(const char* s, char** data, size_t* length) {
aeab07
+  size_t l=strlen(s);
aeab07
   if ((l % 2) == 0) {
aeab07
     delete [] *data;
aeab07
     *data = 0; *length = 0;
aeab07
@@ -59,7 +59,7 @@ bool HexInStream::hexStrToBin(const char* s, char** data, int* length) {
aeab07
       return true;
aeab07
     *data = new char[l/2];
aeab07
     *length = l/2;
aeab07
-    for(int i=0;i
aeab07
+    for(size_t i=0;i
aeab07
       int byte = 0;
aeab07
       if (!readHexAndShift(s[i], &byte) ||
aeab07
         !readHexAndShift(s[i+1], &byte))
aeab07
@@ -76,11 +76,11 @@ decodeError:
aeab07
 }
aeab07
 
aeab07
 
aeab07
-int HexInStream::pos() {
aeab07
+size_t HexInStream::pos() {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
 
aeab07
-int HexInStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
+size_t HexInStream::overrun(size_t itemSize, size_t nItems, bool wait) {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("HexInStream overrun: max itemSize exceeded");
aeab07
 
aeab07
@@ -92,14 +92,14 @@ int HexInStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
   ptr = start;
aeab07
 
aeab07
   while (end < ptr + itemSize) {
aeab07
-    int n = in_stream.check(2, 1, wait);
aeab07
+    size_t n = in_stream.check(2, 1, wait);
aeab07
     if (n == 0) return 0;
aeab07
     const U8* iptr = in_stream.getptr();
aeab07
     const U8* eptr = in_stream.getend();
aeab07
-    int length = min((eptr - iptr)/2, start + bufSize - end);
aeab07
+    size_t length = min((eptr - iptr)/2, start + bufSize - end);
aeab07
 
aeab07
     U8* optr = (U8*) end;
aeab07
-    for (int i=0; i
aeab07
+    for (size_t i=0; i
aeab07
       int v = 0;
aeab07
       readHexAndShift(iptr[i*2], &v);
aeab07
       readHexAndShift(iptr[i*2+1], &v);
aeab07
@@ -110,7 +110,7 @@ int HexInStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
     end += length;
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
diff --git a/common/rdr/HexInStream.h b/common/rdr/HexInStream.h
aeab07
index 6bfb843..8e495fb 100644
aeab07
--- a/common/rdr/HexInStream.h
aeab07
+++ b/common/rdr/HexInStream.h
aeab07
@@ -26,21 +26,21 @@ namespace rdr {
aeab07
   class HexInStream : public InStream {
aeab07
   public:
aeab07
 
aeab07
-    HexInStream(InStream& is, int bufSize=0);
aeab07
+    HexInStream(InStream& is, size_t bufSize=0);
aeab07
     virtual ~HexInStream();
aeab07
 
aeab07
-    int pos();
aeab07
+    size_t pos();
aeab07
 
aeab07
     static bool readHexAndShift(char c, int* v);
aeab07
-    static bool hexStrToBin(const char* s, char** data, int* length);
aeab07
+    static bool hexStrToBin(const char* s, char** data, size_t* length);
aeab07
 
aeab07
   protected:
aeab07
-    int overrun(int itemSize, int nItems, bool wait);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait);
aeab07
 
aeab07
   private:
aeab07
-    int bufSize;
aeab07
+    size_t bufSize;
aeab07
     U8* start;
aeab07
-    int offset;
aeab07
+    size_t offset;
aeab07
 
aeab07
     InStream& in_stream;
aeab07
   };
aeab07
diff --git a/common/rdr/HexOutStream.cxx b/common/rdr/HexOutStream.cxx
aeab07
index 9b0b6c4..7232514 100644
aeab07
--- a/common/rdr/HexOutStream.cxx
aeab07
+++ b/common/rdr/HexOutStream.cxx
aeab07
@@ -23,9 +23,9 @@ using namespace rdr;
aeab07
 
aeab07
 const int DEFAULT_BUF_LEN = 16384;
aeab07
 
aeab07
-static inline int min(int a, int b) {return a
aeab07
+static inline size_t min(size_t a, size_t b) {return a
aeab07
 
aeab07
-HexOutStream::HexOutStream(OutStream& os, int buflen)
aeab07
+HexOutStream::HexOutStream(OutStream& os, size_t buflen)
aeab07
 : out_stream(os), offset(0), bufSize(buflen ? buflen : DEFAULT_BUF_LEN)
aeab07
 {
aeab07
   if (bufSize % 2)
aeab07
@@ -48,9 +48,9 @@ char HexOutStream::intToHex(int i) {
aeab07
     throw rdr::Exception("intToHex failed");
aeab07
 }
aeab07
 
aeab07
-char* HexOutStream::binToHexStr(const char* data, int length) {
aeab07
+char* HexOutStream::binToHexStr(const char* data, size_t length) {
aeab07
   char* buffer = new char[length*2+1];
aeab07
-  for (int i=0; i
aeab07
+  for (size_t i=0; i
aeab07
     buffer[i*2] = intToHex((data[i] >> 4) & 15);
aeab07
     buffer[i*2+1] = intToHex((data[i] & 15));
aeab07
     if (!buffer[i*2] || !buffer[i*2+1]) {
aeab07
@@ -70,9 +70,9 @@ HexOutStream::writeBuffer() {
aeab07
     out_stream.check(2);
aeab07
     U8* optr = out_stream.getptr();
aeab07
     U8* oend = out_stream.getend();
aeab07
-    int length = min(ptr-pos, (oend-optr)/2);
aeab07
+    size_t length = min(ptr-pos, (oend-optr)/2);
aeab07
 
aeab07
-    for (int i=0; i
aeab07
+    for (size_t i=0; i
aeab07
       optr[i*2] = intToHex((pos[i] >> 4) & 0xf);
aeab07
       optr[i*2+1] = intToHex(pos[i] & 0xf);
aeab07
     }
aeab07
@@ -84,7 +84,7 @@ HexOutStream::writeBuffer() {
aeab07
   ptr = start;
aeab07
 }
aeab07
 
aeab07
-int HexOutStream::length()
aeab07
+size_t HexOutStream::length()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
@@ -95,14 +95,14 @@ HexOutStream::flush() {
aeab07
   out_stream.flush();
aeab07
 }
aeab07
 
aeab07
-int
aeab07
-HexOutStream::overrun(int itemSize, int nItems) {
aeab07
+size_t
aeab07
+HexOutStream::overrun(size_t itemSize, size_t nItems) {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("HexOutStream overrun: max itemSize exceeded");
aeab07
 
aeab07
   writeBuffer();
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
diff --git a/common/rdr/HexOutStream.h b/common/rdr/HexOutStream.h
aeab07
index 10247e6..92442a7 100644
aeab07
--- a/common/rdr/HexOutStream.h
aeab07
+++ b/common/rdr/HexOutStream.h
aeab07
@@ -26,24 +26,24 @@ namespace rdr {
aeab07
   class HexOutStream : public OutStream {
aeab07
   public:
aeab07
 
aeab07
-    HexOutStream(OutStream& os, int buflen=0);
aeab07
+    HexOutStream(OutStream& os, size_t buflen=0);
aeab07
     virtual ~HexOutStream();
aeab07
 
aeab07
     void flush();
aeab07
-    int length();
aeab07
+    size_t length();
aeab07
 
aeab07
     static char intToHex(int i);
aeab07
-    static char* binToHexStr(const char* data, int length);
aeab07
+    static char* binToHexStr(const char* data, size_t length);
aeab07
 
aeab07
   private:
aeab07
     void writeBuffer();
aeab07
-    int overrun(int itemSize, int nItems);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems);
aeab07
 
aeab07
     OutStream& out_stream;
aeab07
 
aeab07
     U8* start;
aeab07
-    int offset;
aeab07
-    int bufSize;
aeab07
+    size_t offset;
aeab07
+    size_t bufSize;
aeab07
   };
aeab07
 
aeab07
 }
aeab07
diff --git a/common/rdr/InStream.h b/common/rdr/InStream.h
aeab07
index 212a2ec..14ecf09 100644
aeab07
--- a/common/rdr/InStream.h
aeab07
+++ b/common/rdr/InStream.h
aeab07
@@ -41,7 +41,7 @@ namespace rdr {
aeab07
     // for the bytes, zero is returned if the bytes are not immediately
aeab07
     // available.
aeab07
 
aeab07
-    inline int check(int itemSize, int nItems=1, bool wait=true)
aeab07
+    inline size_t check(size_t itemSize, size_t nItems=1, bool wait=true)
aeab07
     {
aeab07
       if (ptr + itemSize * nItems > end) {
aeab07
         if (ptr + itemSize > end)
aeab07
@@ -56,7 +56,7 @@ namespace rdr {
aeab07
     // be read without blocking.  It returns true if this is the case, false
aeab07
     // otherwise.  The length must be "small" (less than the buffer size).
aeab07
 
aeab07
-    inline bool checkNoWait(int length) { return check(length, 1, false)!=0; }
aeab07
+    inline bool checkNoWait(size_t length) { return check(length, 1, false)!=0; }
aeab07
 
aeab07
     // readU/SN() methods read unsigned and signed N-bit integers.
aeab07
 
aeab07
@@ -82,9 +82,9 @@ namespace rdr {
aeab07
 
aeab07
     static U32 maxStringLength;
aeab07
 
aeab07
-    inline void skip(int bytes) {
aeab07
+    inline void skip(size_t bytes) {
aeab07
       while (bytes > 0) {
aeab07
-        int n = check(1, bytes);
aeab07
+        size_t n = check(1, bytes);
aeab07
         ptr += n;
aeab07
         bytes -= n;
aeab07
       }
aeab07
@@ -92,11 +92,11 @@ namespace rdr {
aeab07
 
aeab07
     // readBytes() reads an exact number of bytes.
aeab07
 
aeab07
-    void readBytes(void* data, int length) {
aeab07
+    void readBytes(void* data, size_t length) {
aeab07
       U8* dataPtr = (U8*)data;
aeab07
       U8* dataEnd = dataPtr + length;
aeab07
       while (dataPtr < dataEnd) {
aeab07
-        int n = check(1, dataEnd - dataPtr);
aeab07
+        size_t n = check(1, dataEnd - dataPtr);
aeab07
         memcpy(dataPtr, ptr, n);
aeab07
         ptr += n;
aeab07
         dataPtr += n;
aeab07
@@ -114,7 +114,7 @@ namespace rdr {
aeab07
 
aeab07
     // pos() returns the position in the stream.
aeab07
 
aeab07
-    virtual int pos() = 0;
aeab07
+    virtual size_t pos() = 0;
aeab07
 
aeab07
     // getptr(), getend() and setptr() are "dirty" methods which allow you to
aeab07
     // manipulate the buffer directly.  This is useful for a stream which is a
aeab07
@@ -133,7 +133,7 @@ namespace rdr {
aeab07
     // instead of blocking to wait for the bytes, zero is returned if the bytes
aeab07
     // are not immediately available.
aeab07
 
aeab07
-    virtual int overrun(int itemSize, int nItems, bool wait=true) = 0;
aeab07
+    virtual size_t overrun(size_t itemSize, size_t nItems, bool wait=true) = 0;
aeab07
 
aeab07
   protected:
aeab07
 
aeab07
diff --git a/common/rdr/MemInStream.h b/common/rdr/MemInStream.h
aeab07
index 1a6a798..3e9e77b 100644
aeab07
--- a/common/rdr/MemInStream.h
aeab07
+++ b/common/rdr/MemInStream.h
aeab07
@@ -36,7 +36,7 @@ namespace rdr {
aeab07
 
aeab07
   public:
aeab07
 
aeab07
-    MemInStream(const void* data, int len, bool deleteWhenDone_=false)
aeab07
+    MemInStream(const void* data, size_t len, bool deleteWhenDone_=false)
aeab07
       : start((const U8*)data), deleteWhenDone(deleteWhenDone_)
aeab07
     {
aeab07
       ptr = start;
aeab07
@@ -48,12 +48,12 @@ namespace rdr {
aeab07
         delete [] start;
aeab07
     }
aeab07
 
aeab07
-    int pos() { return ptr - start; }
aeab07
-    void reposition(int pos) { ptr = start + pos; }
aeab07
+    size_t pos() { return ptr - start; }
aeab07
+    void reposition(size_t pos) { ptr = start + pos; }
aeab07
 
aeab07
   private:
aeab07
 
aeab07
-    int overrun(int itemSize, int nItems, bool wait) { throw EndOfStream(); }
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait) { throw EndOfStream(); }
aeab07
     const U8* start;
aeab07
     bool deleteWhenDone;
aeab07
   };
aeab07
diff --git a/common/rdr/MemOutStream.h b/common/rdr/MemOutStream.h
aeab07
index 3b17e55..4a815b3 100644
aeab07
--- a/common/rdr/MemOutStream.h
aeab07
+++ b/common/rdr/MemOutStream.h
aeab07
@@ -40,16 +40,16 @@ namespace rdr {
aeab07
       delete [] start;
aeab07
     }
aeab07
 
aeab07
-    void writeBytes(const void* data, int length) {
aeab07
+    void writeBytes(const void* data, size_t length) {
aeab07
       check(length);
aeab07
       memcpy(ptr, data, length);
aeab07
       ptr += length;
aeab07
     }
aeab07
 
aeab07
-    int length() { return ptr - start; }
aeab07
+    size_t length() { return ptr - start; }
aeab07
     void clear() { ptr = start; };
aeab07
     void clearAndZero() { memset(start, 0, ptr-start); clear(); }
aeab07
-    void reposition(int pos) { ptr = start + pos; }
aeab07
+    void reposition(size_t pos) { ptr = start + pos; }
aeab07
 
aeab07
     // data() returns a pointer to the buffer.
aeab07
 
aeab07
@@ -60,9 +60,9 @@ namespace rdr {
aeab07
     // overrun() either doubles the buffer or adds enough space for nItems of
aeab07
     // size itemSize bytes.
aeab07
 
aeab07
-    int overrun(int itemSize, int nItems) {
aeab07
-      int len = ptr - start + itemSize * nItems;
aeab07
-      if (len < (end - start) * 2)
aeab07
+    size_t overrun(size_t itemSize, size_t nItems) {
aeab07
+      size_t len = ptr - start + itemSize * nItems;
aeab07
+      if (len < (size_t)(end - start) * 2)
aeab07
         len = (end - start) * 2;
aeab07
 
aeab07
       U8* newStart = new U8[len];
aeab07
diff --git a/common/rdr/OutStream.h b/common/rdr/OutStream.h
aeab07
index a749a20..11aafd2 100644
aeab07
--- a/common/rdr/OutStream.h
aeab07
+++ b/common/rdr/OutStream.h
aeab07
@@ -44,7 +44,7 @@ namespace rdr {
aeab07
     // itemSize bytes.  Returns the number of items which fit (up to a maximum
aeab07
     // of nItems).
aeab07
 
aeab07
-    inline int check(int itemSize, int nItems=1)
aeab07
+    inline size_t check(size_t itemSize, size_t nItems=1)
aeab07
     {
aeab07
       if (ptr + itemSize * nItems > end) {
aeab07
         if (ptr + itemSize > end)
aeab07
@@ -76,13 +76,13 @@ namespace rdr {
aeab07
       writeBytes(str, len);
aeab07
     }
aeab07
 
aeab07
-    inline void pad(int bytes) {
aeab07
+    inline void pad(size_t bytes) {
aeab07
       while (bytes-- > 0) writeU8(0);
aeab07
     }
aeab07
 
aeab07
-    inline void skip(int bytes) {
aeab07
+    inline void skip(size_t bytes) {
aeab07
       while (bytes > 0) {
aeab07
-        int n = check(1, bytes);
aeab07
+        size_t n = check(1, bytes);
aeab07
         ptr += n;
aeab07
         bytes -= n;
aeab07
       }
aeab07
@@ -90,11 +90,11 @@ namespace rdr {
aeab07
 
aeab07
     // writeBytes() writes an exact number of bytes.
aeab07
 
aeab07
-    void writeBytes(const void* data, int length) {
aeab07
+    void writeBytes(const void* data, size_t length) {
aeab07
       const U8* dataPtr = (const U8*)data;
aeab07
       const U8* dataEnd = dataPtr + length;
aeab07
       while (dataPtr < dataEnd) {
aeab07
-        int n = check(1, dataEnd - dataPtr);
aeab07
+        size_t n = check(1, dataEnd - dataPtr);
aeab07
         memcpy(ptr, dataPtr, n);
aeab07
         ptr += n;
aeab07
         dataPtr += n;
aeab07
@@ -103,9 +103,9 @@ namespace rdr {
aeab07
 
aeab07
     // copyBytes() efficiently transfers data between streams
aeab07
 
aeab07
-    void copyBytes(InStream* is, int length) {
aeab07
+    void copyBytes(InStream* is, size_t length) {
aeab07
       while (length > 0) {
aeab07
-        int n = check(1, length);
aeab07
+        size_t n = check(1, length);
aeab07
         is->readBytes(ptr, n);
aeab07
         ptr += n;
aeab07
         length -= n;
aeab07
@@ -124,7 +124,7 @@ namespace rdr {
aeab07
 
aeab07
     // length() returns the length of the stream.
aeab07
 
aeab07
-    virtual int length() = 0;
aeab07
+    virtual size_t length() = 0;
aeab07
 
aeab07
     // flush() requests that the stream be flushed.
aeab07
 
aeab07
@@ -145,7 +145,7 @@ namespace rdr {
aeab07
     // the number of items which fit (up to a maximum of nItems).  itemSize is
aeab07
     // supposed to be "small" (a few bytes).
aeab07
 
aeab07
-    virtual int overrun(int itemSize, int nItems) = 0;
aeab07
+    virtual size_t overrun(size_t itemSize, size_t nItems) = 0;
aeab07
 
aeab07
   protected:
aeab07
 
aeab07
diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx
aeab07
index 3fde18d..7681095 100644
aeab07
--- a/common/rdr/RandomStream.cxx
aeab07
+++ b/common/rdr/RandomStream.cxx
aeab07
@@ -32,7 +32,7 @@
aeab07
 
aeab07
 using namespace rdr;
aeab07
 
aeab07
-const int DEFAULT_BUF_LEN = 256;
aeab07
+const size_t DEFAULT_BUF_LEN = 256;
aeab07
 
aeab07
 unsigned int RandomStream::seed;
aeab07
 
aeab07
@@ -83,11 +83,11 @@ RandomStream::~RandomStream() {
aeab07
 #endif
aeab07
 }
aeab07
 
aeab07
-int RandomStream::pos() {
aeab07
+size_t RandomStream::pos() {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
 
aeab07
-int RandomStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
+size_t RandomStream::overrun(size_t itemSize, size_t nItems, bool wait) {
aeab07
   if (itemSize > DEFAULT_BUF_LEN)
aeab07
     throw Exception("RandomStream overrun: max itemSize exceeded");
aeab07
 
aeab07
@@ -98,7 +98,7 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
   offset += ptr - start;
aeab07
   ptr = start;
aeab07
 
aeab07
-  int length = start + DEFAULT_BUF_LEN - end;
aeab07
+  size_t length = start + DEFAULT_BUF_LEN - end;
aeab07
 
aeab07
 #ifdef RFB_HAVE_WINCRYPT
aeab07
   if (provider) {
aeab07
@@ -109,7 +109,7 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
 #else
aeab07
 #ifndef WIN32
aeab07
   if (fp) {
aeab07
-    int n = fread((U8*)end, length, 1, fp);
aeab07
+    size_t n = fread((U8*)end, length, 1, fp);
aeab07
     if (n != 1)
aeab07
       throw rdr::SystemException("reading /dev/urandom or /dev/random failed",
aeab07
                                  errno);
aeab07
@@ -119,11 +119,11 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
aeab07
   {
aeab07
 #endif
aeab07
 #endif
aeab07
-    for (int i=0; i
aeab07
+    for (size_t i=0; i
aeab07
       *(U8*)end++ = (int) (256.0*rand()/(RAND_MAX+1.0));
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
diff --git a/common/rdr/RandomStream.h b/common/rdr/RandomStream.h
aeab07
index c33360d..80b389b 100644
aeab07
--- a/common/rdr/RandomStream.h
aeab07
+++ b/common/rdr/RandomStream.h
aeab07
@@ -39,14 +39,14 @@ namespace rdr {
aeab07
     RandomStream();
aeab07
     virtual ~RandomStream();
aeab07
 
aeab07
-    int pos();
aeab07
+    size_t pos();
aeab07
 
aeab07
   protected:
aeab07
-    int overrun(int itemSize, int nItems, bool wait);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait);
aeab07
 
aeab07
   private:
aeab07
     U8* start;
aeab07
-    int offset;
aeab07
+    size_t offset;
aeab07
 
aeab07
     static unsigned int seed;
aeab07
 #ifdef RFB_HAVE_WINCRYPT
aeab07
diff --git a/common/rdr/SubstitutingInStream.h b/common/rdr/SubstitutingInStream.h
aeab07
index 325b01c..1466fef 100644
aeab07
--- a/common/rdr/SubstitutingInStream.h
aeab07
+++ b/common/rdr/SubstitutingInStream.h
aeab07
@@ -45,9 +45,9 @@ namespace rdr {
aeab07
       delete [] subst;
aeab07
     }
aeab07
 
aeab07
-    int pos() { return underlying->pos(); }
aeab07
+    size_t pos() { return underlying->pos(); }
aeab07
 
aeab07
-    virtual int overrun(int itemSize, int nItems, bool wait=true) {
aeab07
+    virtual size_t overrun(size_t itemSize, size_t nItems, bool wait=true) {
aeab07
       if (itemSize != 1)
aeab07
         throw new rdr::Exception("SubstitutingInStream: itemSize must be 1");
aeab07
 
aeab07
diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx
aeab07
index 77b1672..d0f9426 100644
aeab07
--- a/common/rdr/TLSInStream.cxx
aeab07
+++ b/common/rdr/TLSInStream.cxx
aeab07
@@ -75,12 +75,12 @@ TLSInStream::~TLSInStream()
aeab07
   delete[] start;
aeab07
 }
aeab07
 
aeab07
-int TLSInStream::pos()
aeab07
+size_t TLSInStream::pos()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
 
aeab07
-int TLSInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
+size_t TLSInStream::overrun(size_t itemSize, size_t nItems, bool wait)
aeab07
 {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("TLSInStream overrun: max itemSize exceeded");
aeab07
@@ -93,19 +93,19 @@ int TLSInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
   ptr = start;
aeab07
 
aeab07
   while (end < start + itemSize) {
aeab07
-    int n = readTLS((U8*) end, start + bufSize - end, wait);
aeab07
+    size_t n = readTLS((U8*) end, start + bufSize - end, wait);
aeab07
     if (!wait && n == 0)
aeab07
       return 0;
aeab07
     end += n;
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
 }
aeab07
 
aeab07
-int TLSInStream::readTLS(U8* buf, int len, bool wait)
aeab07
+size_t TLSInStream::readTLS(U8* buf, size_t len, bool wait)
aeab07
 {
aeab07
   int n;
aeab07
 
aeab07
diff --git a/common/rdr/TLSInStream.h b/common/rdr/TLSInStream.h
aeab07
index b16d9f5..5f9dee7 100644
aeab07
--- a/common/rdr/TLSInStream.h
aeab07
+++ b/common/rdr/TLSInStream.h
aeab07
@@ -36,17 +36,17 @@ namespace rdr {
aeab07
     TLSInStream(InStream* in, gnutls_session_t session);
aeab07
     virtual ~TLSInStream();
aeab07
 
aeab07
-    int pos();
aeab07
+    size_t pos();
aeab07
 
aeab07
   private:
aeab07
-    int overrun(int itemSize, int nItems, bool wait);
aeab07
-    int readTLS(U8* buf, int len, bool wait);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait);
aeab07
+    size_t readTLS(U8* buf, size_t len, bool wait);
aeab07
     static ssize_t pull(gnutls_transport_ptr_t str, void* data, size_t size);
aeab07
 
aeab07
     gnutls_session_t session;
aeab07
     InStream* in;
aeab07
-    int bufSize;
aeab07
-    int offset;
aeab07
+    size_t bufSize;
aeab07
+    size_t offset;
aeab07
     U8* start;
aeab07
   };
aeab07
 };
aeab07
diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx
aeab07
index 44d2d9f..30c456f 100644
aeab07
--- a/common/rdr/TLSOutStream.cxx
aeab07
+++ b/common/rdr/TLSOutStream.cxx
aeab07
@@ -75,7 +75,7 @@ TLSOutStream::~TLSOutStream()
aeab07
   delete [] start;
aeab07
 }
aeab07
 
aeab07
-int TLSOutStream::length()
aeab07
+size_t TLSOutStream::length()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
@@ -84,7 +84,7 @@ void TLSOutStream::flush()
aeab07
 {
aeab07
   U8* sentUpTo = start;
aeab07
   while (sentUpTo < ptr) {
aeab07
-    int n = writeTLS(sentUpTo, ptr - sentUpTo);
aeab07
+    size_t n = writeTLS(sentUpTo, ptr - sentUpTo);
aeab07
     sentUpTo += n;
aeab07
     offset += n;
aeab07
   }
aeab07
@@ -93,20 +93,20 @@ void TLSOutStream::flush()
aeab07
   out->flush();
aeab07
 }
aeab07
 
aeab07
-int TLSOutStream::overrun(int itemSize, int nItems)
aeab07
+size_t TLSOutStream::overrun(size_t itemSize, size_t nItems)
aeab07
 {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("TLSOutStream overrun: max itemSize exceeded");
aeab07
 
aeab07
   flush();
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
 }
aeab07
 
aeab07
-int TLSOutStream::writeTLS(const U8* data, int length)
aeab07
+size_t TLSOutStream::writeTLS(const U8* data, size_t length)
aeab07
 {
aeab07
   int n;
aeab07
 
aeab07
diff --git a/common/rdr/TLSOutStream.h b/common/rdr/TLSOutStream.h
aeab07
index 81dd237..71a7f3b 100644
aeab07
--- a/common/rdr/TLSOutStream.h
aeab07
+++ b/common/rdr/TLSOutStream.h
aeab07
@@ -36,20 +36,20 @@ namespace rdr {
aeab07
     virtual ~TLSOutStream();
aeab07
 
aeab07
     void flush();
aeab07
-    int length();
aeab07
+    size_t length();
aeab07
 
aeab07
   protected:
aeab07
-    int overrun(int itemSize, int nItems);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems);
aeab07
 
aeab07
   private:
aeab07
-    int writeTLS(const U8* data, int length);
aeab07
+    size_t writeTLS(const U8* data, size_t length);
aeab07
     static ssize_t push(gnutls_transport_ptr_t str, const void* data, size_t size);
aeab07
 
aeab07
     gnutls_session_t session;
aeab07
     OutStream* out;
aeab07
-    int bufSize;
aeab07
+    size_t bufSize;
aeab07
     U8* start;
aeab07
-    int offset;
aeab07
+    size_t offset;
aeab07
   };
aeab07
 };
aeab07
 
aeab07
diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx
aeab07
index a361010..e2f971c 100644
aeab07
--- a/common/rdr/ZlibInStream.cxx
aeab07
+++ b/common/rdr/ZlibInStream.cxx
aeab07
@@ -26,7 +26,7 @@ using namespace rdr;
aeab07
 
aeab07
 enum { DEFAULT_BUF_SIZE = 16384 };
aeab07
 
aeab07
-ZlibInStream::ZlibInStream(int bufSize_)
aeab07
+ZlibInStream::ZlibInStream(size_t bufSize_)
aeab07
   : underlying(0), bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0),
aeab07
     zs(NULL), bytesIn(0)
aeab07
 {
aeab07
@@ -40,14 +40,14 @@ ZlibInStream::~ZlibInStream()
aeab07
   delete [] start;
aeab07
 }
aeab07
 
aeab07
-void ZlibInStream::setUnderlying(InStream* is, int bytesIn_)
aeab07
+void ZlibInStream::setUnderlying(InStream* is, size_t bytesIn_)
aeab07
 {
aeab07
   underlying = is;
aeab07
   bytesIn = bytesIn_;
aeab07
   ptr = end = start;
aeab07
 }
aeab07
 
aeab07
-int ZlibInStream::pos()
aeab07
+size_t ZlibInStream::pos()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
@@ -96,7 +96,7 @@ void ZlibInStream::deinit()
aeab07
   zs = NULL;
aeab07
 }
aeab07
 
aeab07
-int ZlibInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
+size_t ZlibInStream::overrun(size_t itemSize, size_t nItems, bool wait)
aeab07
 {
aeab07
   if (itemSize > bufSize)
aeab07
     throw Exception("ZlibInStream overrun: max itemSize exceeded");
aeab07
@@ -108,12 +108,12 @@ int ZlibInStream::overrun(int itemSize, int nItems, bool wait)
aeab07
   end -= ptr - start;
aeab07
   ptr = start;
aeab07
 
aeab07
-  while (end - ptr < itemSize) {
aeab07
+  while ((size_t)(end - ptr) < itemSize) {
aeab07
     if (!decompress(wait))
aeab07
       return 0;
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
@@ -131,11 +131,11 @@ bool ZlibInStream::decompress(bool wait)
aeab07
   zs->next_out = (U8*)end;
aeab07
   zs->avail_out = start + bufSize - end;
aeab07
 
aeab07
-  int n = underlying->check(1, 1, wait);
aeab07
+  size_t n = underlying->check(1, 1, wait);
aeab07
   if (n == 0) return false;
aeab07
   zs->next_in = (U8*)underlying->getptr();
aeab07
   zs->avail_in = underlying->getend() - underlying->getptr();
aeab07
-  if ((int)zs->avail_in > bytesIn)
aeab07
+  if (zs->avail_in > bytesIn)
aeab07
     zs->avail_in = bytesIn;
aeab07
 
aeab07
   int rc = inflate(zs, Z_SYNC_FLUSH);
aeab07
diff --git a/common/rdr/ZlibInStream.h b/common/rdr/ZlibInStream.h
aeab07
index 86ba1ff..08784b0 100644
aeab07
--- a/common/rdr/ZlibInStream.h
aeab07
+++ b/common/rdr/ZlibInStream.h
aeab07
@@ -34,12 +34,12 @@ namespace rdr {
aeab07
 
aeab07
   public:
aeab07
 
aeab07
-    ZlibInStream(int bufSize=0);
aeab07
+    ZlibInStream(size_t bufSize=0);
aeab07
     virtual ~ZlibInStream();
aeab07
 
aeab07
-    void setUnderlying(InStream* is, int bytesIn);
aeab07
+    void setUnderlying(InStream* is, size_t bytesIn);
aeab07
     void flushUnderlying();
aeab07
-    int pos();
aeab07
+    size_t pos();
aeab07
     void reset();
aeab07
 
aeab07
   private:
aeab07
@@ -47,14 +47,14 @@ namespace rdr {
aeab07
     void init();
aeab07
     void deinit();
aeab07
 
aeab07
-    int overrun(int itemSize, int nItems, bool wait);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems, bool wait);
aeab07
     bool decompress(bool wait);
aeab07
 
aeab07
     InStream* underlying;
aeab07
-    int bufSize;
aeab07
-    int offset;
aeab07
+    size_t bufSize;
aeab07
+    size_t offset;
aeab07
     z_stream_s* zs;
aeab07
-    int bytesIn;
aeab07
+    size_t bytesIn;
aeab07
     U8* start;
aeab07
   };
aeab07
 
aeab07
diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx
aeab07
index 9d9f8ba..4e7ffd6 100644
aeab07
--- a/common/rdr/ZlibOutStream.cxx
aeab07
+++ b/common/rdr/ZlibOutStream.cxx
aeab07
@@ -30,7 +30,7 @@ using namespace rdr;
aeab07
 
aeab07
 enum { DEFAULT_BUF_SIZE = 16384 };
aeab07
 
aeab07
-ZlibOutStream::ZlibOutStream(OutStream* os, int bufSize_, int compressLevel)
aeab07
+ZlibOutStream::ZlibOutStream(OutStream* os, size_t bufSize_, int compressLevel)
aeab07
   : underlying(os), compressionLevel(compressLevel), newLevel(compressLevel),
aeab07
     bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
aeab07
 {
aeab07
@@ -72,7 +72,7 @@ void ZlibOutStream::setCompressionLevel(int level)
aeab07
   newLevel = level;
aeab07
 }
aeab07
 
aeab07
-int ZlibOutStream::length()
aeab07
+size_t ZlibOutStream::length()
aeab07
 {
aeab07
   return offset + ptr - start;
aeab07
 }
aeab07
@@ -95,7 +95,7 @@ void ZlibOutStream::flush()
aeab07
   ptr = start;
aeab07
 }
aeab07
 
aeab07
-int ZlibOutStream::overrun(int itemSize, int nItems)
aeab07
+size_t ZlibOutStream::overrun(size_t itemSize, size_t nItems)
aeab07
 {
aeab07
 #ifdef ZLIBOUT_DEBUG
aeab07
   fprintf(stderr,"zos overrun\n");
aeab07
@@ -106,7 +106,7 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
aeab07
 
aeab07
   checkCompressionLevel();
aeab07
 
aeab07
-  while (end - ptr < itemSize) {
aeab07
+  while ((size_t)(end - ptr) < itemSize) {
aeab07
     zs->next_in = start;
aeab07
     zs->avail_in = ptr - start;
aeab07
 
aeab07
@@ -127,7 +127,7 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
aeab07
     }
aeab07
   }
aeab07
 
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
 
aeab07
   return nItems;
aeab07
diff --git a/common/rdr/ZlibOutStream.h b/common/rdr/ZlibOutStream.h
aeab07
index 2d82a13..11bb046 100644
aeab07
--- a/common/rdr/ZlibOutStream.h
aeab07
+++ b/common/rdr/ZlibOutStream.h
aeab07
@@ -35,25 +35,25 @@ namespace rdr {
aeab07
 
aeab07
   public:
aeab07
 
aeab07
-    ZlibOutStream(OutStream* os=0, int bufSize=0, int compressionLevel=-1);
aeab07
+    ZlibOutStream(OutStream* os=0, size_t bufSize=0, int compressionLevel=-1);
aeab07
     virtual ~ZlibOutStream();
aeab07
 
aeab07
     void setUnderlying(OutStream* os);
aeab07
     void setCompressionLevel(int level=-1);
aeab07
     void flush();
aeab07
-    int length();
aeab07
+    size_t length();
aeab07
 
aeab07
   private:
aeab07
 
aeab07
-    int overrun(int itemSize, int nItems);
aeab07
+    size_t overrun(size_t itemSize, size_t nItems);
aeab07
     void deflate(int flush);
aeab07
     void checkCompressionLevel();
aeab07
 
aeab07
     OutStream* underlying;
aeab07
     int compressionLevel;
aeab07
     int newLevel;
aeab07
-    int bufSize;
aeab07
-    int offset;
aeab07
+    size_t bufSize;
aeab07
+    size_t offset;
aeab07
     z_stream_s* zs;
aeab07
     U8* start;
aeab07
   };
aeab07
diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx
aeab07
index 619c4d5..f35b0bc 100644
aeab07
--- a/common/rfb/Configuration.cxx
aeab07
+++ b/common/rfb/Configuration.cxx
aeab07
@@ -421,7 +421,7 @@ StringParameter::operator const char *() const {
aeab07
 // -=- BinaryParameter
aeab07
 
aeab07
 BinaryParameter::BinaryParameter(const char* name_, const char* desc_,
aeab07
-				 const void* v, int l, ConfigurationObject co)
aeab07
+				 const void* v, size_t l, ConfigurationObject co)
aeab07
 : VoidParameter(name_, desc_, co), value(0), length(0), def_value((char*)v), def_length(l) {
aeab07
   if (l) {
aeab07
     value = new char[l];
aeab07
@@ -441,7 +441,7 @@ bool BinaryParameter::setParam(const char* v) {
aeab07
   return rdr::HexInStream::hexStrToBin(v, &value, &length);
aeab07
 }
aeab07
 
aeab07
-void BinaryParameter::setParam(const void* v, int len) {
aeab07
+void BinaryParameter::setParam(const void* v, size_t len) {
aeab07
   LOCK_CONFIG;
aeab07
   if (immutable) return; 
aeab07
   vlog.debug("set %s(Binary)", getName());
aeab07
@@ -462,7 +462,7 @@ char* BinaryParameter::getValueStr() const {
aeab07
   return rdr::HexOutStream::binToHexStr(value, length);
aeab07
 }
aeab07
 
aeab07
-void BinaryParameter::getData(void** data_, int* length_) const {
aeab07
+void BinaryParameter::getData(void** data_, size_t* length_) const {
aeab07
   LOCK_CONFIG;
aeab07
   if (length_) *length_ = length;
aeab07
   if (data_) {
aeab07
diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h
aeab07
index 6197317..e23e8a5 100644
aeab07
--- a/common/rfb/Configuration.h
aeab07
+++ b/common/rfb/Configuration.h
aeab07
@@ -256,24 +256,25 @@ namespace rfb {
aeab07
 
aeab07
   class BinaryParameter : public VoidParameter {
aeab07
   public:
aeab07
-    BinaryParameter(const char* name_, const char* desc_, const void* v, int l,
aeab07
-		    ConfigurationObject co=ConfGlobal);
aeab07
+    BinaryParameter(const char* name_, const char* desc_,
aeab07
+                    const void* v, size_t l,
aeab07
+                    ConfigurationObject co=ConfGlobal);
aeab07
     using VoidParameter::setParam;
aeab07
     virtual ~BinaryParameter();
aeab07
     virtual bool setParam(const char* value);
aeab07
-    virtual void setParam(const void* v, int l);
aeab07
+    virtual void setParam(const void* v, size_t l);
aeab07
     virtual char* getDefaultStr() const;
aeab07
     virtual char* getValueStr() const;
aeab07
 
aeab07
     // getData() will return length zero if there is no data
aeab07
     // NB: data may be set to zero, OR set to a zero-length buffer
aeab07
-    void getData(void** data, int* length) const;
aeab07
+    void getData(void** data, size_t* length) const;
aeab07
 
aeab07
   protected:
aeab07
     char* value;
aeab07
-    int length;
aeab07
+    size_t length;
aeab07
     char* def_value;
aeab07
-    int def_length;
aeab07
+    size_t def_length;
aeab07
   };
aeab07
 
aeab07
   // -=- ParameterIterator
aeab07
diff --git a/common/rfb/Password.cxx b/common/rfb/Password.cxx
aeab07
index 240c9d4..e4a508c 100644
aeab07
--- a/common/rfb/Password.cxx
aeab07
+++ b/common/rfb/Password.cxx
aeab07
@@ -38,7 +38,7 @@ PlainPasswd::PlainPasswd() {}
aeab07
 PlainPasswd::PlainPasswd(char* pwd) : CharArray(pwd) {
aeab07
 }
aeab07
 
aeab07
-PlainPasswd::PlainPasswd(int len) : CharArray(len) {
aeab07
+PlainPasswd::PlainPasswd(size_t len) : CharArray(len) {
aeab07
 }
aeab07
 
aeab07
 PlainPasswd::PlainPasswd(const ObfuscatedPasswd& obfPwd) : CharArray(9) {
aeab07
@@ -63,11 +63,11 @@ void PlainPasswd::replaceBuf(char* b) {
aeab07
 ObfuscatedPasswd::ObfuscatedPasswd() : length(0) {
aeab07
 }
aeab07
 
aeab07
-ObfuscatedPasswd::ObfuscatedPasswd(int len) : CharArray(len), length(len) {
aeab07
+ObfuscatedPasswd::ObfuscatedPasswd(size_t len) : CharArray(len), length(len) {
aeab07
 }
aeab07
 
aeab07
 ObfuscatedPasswd::ObfuscatedPasswd(const PlainPasswd& plainPwd) : CharArray(8), length(8) {
aeab07
-  int l = strlen(plainPwd.buf), i;
aeab07
+  size_t l = strlen(plainPwd.buf), i;
aeab07
   for (i=0; i<8; i++)
aeab07
     buf[i] = i
aeab07
   deskey(d3desObfuscationKey, EN0);
aeab07
diff --git a/common/rfb/Password.h b/common/rfb/Password.h
aeab07
index e5196ee..712bc81 100644
aeab07
--- a/common/rfb/Password.h
aeab07
+++ b/common/rfb/Password.h
aeab07
@@ -28,7 +28,7 @@ namespace rfb {
aeab07
   public:
aeab07
     PlainPasswd();
aeab07
     PlainPasswd(char* pwd);
aeab07
-    PlainPasswd(int len);
aeab07
+    PlainPasswd(size_t len);
aeab07
     PlainPasswd(const ObfuscatedPasswd& obfPwd);
aeab07
     ~PlainPasswd();
aeab07
     void replaceBuf(char* b);
aeab07
@@ -37,10 +37,10 @@ namespace rfb {
aeab07
   class ObfuscatedPasswd : public CharArray {
aeab07
   public:
aeab07
     ObfuscatedPasswd();
aeab07
-    ObfuscatedPasswd(int l);
aeab07
+    ObfuscatedPasswd(size_t l);
aeab07
     ObfuscatedPasswd(const PlainPasswd& plainPwd);
aeab07
     ~ObfuscatedPasswd();
aeab07
-    int length;
aeab07
+    size_t length;
aeab07
   };
aeab07
 
aeab07
 }
aeab07
diff --git a/common/rfb/util.h b/common/rfb/util.h
aeab07
index 9e59bd3..8f90ec4 100644
aeab07
--- a/common/rfb/util.h
aeab07
+++ b/common/rfb/util.h
aeab07
@@ -49,7 +49,7 @@ namespace rfb {
aeab07
   public:
aeab07
     CharArray() : buf(0) {}
aeab07
     CharArray(char* str) : buf(str) {} // note: assumes ownership
aeab07
-    CharArray(int len) {
aeab07
+    CharArray(size_t len) {
aeab07
       buf = new char[len]();
aeab07
     }
aeab07
     ~CharArray() {
aeab07
diff --git a/tests/encperf.cxx b/tests/encperf.cxx
aeab07
index 4e7038f..9e3bdbf 100644
aeab07
--- a/tests/encperf.cxx
aeab07
+++ b/tests/encperf.cxx
aeab07
@@ -71,11 +71,11 @@ class DummyOutStream : public rdr::OutStream {
aeab07
 public:
aeab07
   DummyOutStream();
aeab07
 
aeab07
-  virtual int length();
aeab07
+  virtual size_t length();
aeab07
   virtual void flush();
aeab07
 
aeab07
 private:
aeab07
-  virtual int overrun(int itemSize, int nItems);
aeab07
+  virtual size_t overrun(size_t itemSize, size_t nItems);
aeab07
 
aeab07
   int offset;
aeab07
   rdr::U8 buf[131072];
aeab07
@@ -141,7 +141,7 @@ DummyOutStream::DummyOutStream()
aeab07
   end = buf + sizeof(buf);
aeab07
 }
aeab07
 
aeab07
-int DummyOutStream::length()
aeab07
+size_t DummyOutStream::length()
aeab07
 {
aeab07
   flush();
aeab07
   return offset;
aeab07
@@ -153,10 +153,10 @@ void DummyOutStream::flush()
aeab07
   ptr = buf;
aeab07
 }
aeab07
 
aeab07
-int DummyOutStream::overrun(int itemSize, int nItems)
aeab07
+size_t DummyOutStream::overrun(size_t itemSize, size_t nItems)
aeab07
 {
aeab07
   flush();
aeab07
-  if (itemSize * nItems > end - ptr)
aeab07
+  if (itemSize * nItems > (size_t)(end - ptr))
aeab07
     nItems = (end - ptr) / itemSize;
aeab07
   return nItems;
aeab07
 }
aeab07
diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx
aeab07
index 963a36a..87086ad 100644
aeab07
--- a/win/rfb_win32/Registry.cxx
aeab07
+++ b/win/rfb_win32/Registry.cxx
aeab07
@@ -146,7 +146,7 @@ void RegKey::setString(const TCHAR* valname, const TCHAR* value) const {
aeab07
   if (result != ERROR_SUCCESS) throw rdr::SystemException("setString", result);
aeab07
 }
aeab07
 
aeab07
-void RegKey::setBinary(const TCHAR* valname, const void* value, int length) const {
aeab07
+void RegKey::setBinary(const TCHAR* valname, const void* value, size_t length) const {
aeab07
   LONG result = RegSetValueEx(key, valname, 0, REG_BINARY, (const BYTE*)value, length);
aeab07
   if (result != ERROR_SUCCESS) throw rdr::SystemException("setBinary", result);
aeab07
 }
aeab07
@@ -169,12 +169,12 @@ TCHAR* RegKey::getString(const TCHAR* valname, const TCHAR* def) const {
aeab07
   }
aeab07
 }
aeab07
 
aeab07
-void RegKey::getBinary(const TCHAR* valname, void** data, int* length) const {
aeab07
+void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length) const {
aeab07
   TCharArray hex(getRepresentation(valname));
aeab07
   if (!rdr::HexInStream::hexStrToBin(CStr(hex.buf), (char**)data, length))
aeab07
     throw rdr::Exception("getBinary failed");
aeab07
 }
aeab07
-void RegKey::getBinary(const TCHAR* valname, void** data, int* length, void* def, int deflen) const {
aeab07
+void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflen) const {
aeab07
   try {
aeab07
     getBinary(valname, data, length);
aeab07
   } catch(rdr::Exception&) {
aeab07
diff --git a/win/rfb_win32/Registry.h b/win/rfb_win32/Registry.h
aeab07
index 68d535c..2bb1691 100644
aeab07
--- a/win/rfb_win32/Registry.h
aeab07
+++ b/win/rfb_win32/Registry.h
aeab07
@@ -71,15 +71,15 @@ namespace rfb {
aeab07
 
aeab07
       void setExpandString(const TCHAR* valname, const TCHAR* s) const;
aeab07
       void setString(const TCHAR* valname, const TCHAR* s) const;
aeab07
-      void setBinary(const TCHAR* valname, const void* data, int length) const;
aeab07
+      void setBinary(const TCHAR* valname, const void* data, size_t length) const;
aeab07
       void setInt(const TCHAR* valname, int i) const;
aeab07
       void setBool(const TCHAR* valname, bool b) const;
aeab07
 
aeab07
       TCHAR* getString(const TCHAR* valname) const;
aeab07
       TCHAR* getString(const TCHAR* valname, const TCHAR* def) const;
aeab07
 
aeab07
-      void getBinary(const TCHAR* valname, void** data, int* length) const;
aeab07
-      void getBinary(const TCHAR* valname, void** data, int* length, void* def, int deflength) const;
aeab07
+      void getBinary(const TCHAR* valname, void** data, size_t* length) const;
aeab07
+      void getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflength) const;
aeab07
 
aeab07
       int getInt(const TCHAR* valname) const;
aeab07
       int getInt(const TCHAR* valname, int def) const;