diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-06-11 21:51:30 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-06-11 21:51:30 +0700 |
commit | 60e5308f670ed5cd4cac8cb35ac48cbbd283ee26 (patch) | |
tree | 8666b1f41c08956087feec1f569b9b1c6eaf8e68 /crypto/src | |
parent | Add new class Primes (diff) | |
download | BouncyCastle.NET-ed25519-60e5308f670ed5cd4cac8cb35ac48cbbd283ee26.tar.xz |
Improve limit-testing to avoid overflow problems
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/util/io/Streams.cs | 6 |
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; } |