summary refs log tree commit diff
path: root/crypto/src/util/io
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-06-11 21:51:30 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-06-11 21:51:30 +0700
commit60e5308f670ed5cd4cac8cb35ac48cbbd283ee26 (patch)
tree8666b1f41c08956087feec1f569b9b1c6eaf8e68 /crypto/src/util/io
parentAdd new class Primes (diff)
downloadBouncyCastle.NET-ed25519-60e5308f670ed5cd4cac8cb35ac48cbbd283ee26.tar.xz
Improve limit-testing to avoid overflow problems
Diffstat (limited to 'crypto/src/util/io')
-rw-r--r--crypto/src/util/io/Streams.cs6
1 files changed, 3 insertions, 3 deletions
diff --git a/crypto/src/util/io/Streams.cs b/crypto/src/util/io/Streams.cs
index ee95d3b01..70957acc7 100644
--- a/crypto/src/util/io/Streams.cs
+++ b/crypto/src/util/io/Streams.cs
@@ -83,10 +83,10 @@ namespace Org.BouncyCastle.Utilities.IO
 			int numRead;
 			while ((numRead = inStr.Read(bs, 0, bs.Length)) > 0)
 			{
-				total += numRead;
-				if (total > limit)
+                if ((limit - total) < numRead)
 					throw new StreamOverflowException("Data Overflow");
-				outStr.Write(bs, 0, numRead);
+                total += numRead;
+                outStr.Write(bs, 0, numRead);
 			}
 			return total;
 		}