From 60e5308f670ed5cd4cac8cb35ac48cbbd283ee26 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 11 Jun 2015 21:51:30 +0700 Subject: Improve limit-testing to avoid overflow problems --- crypto/src/util/io/Streams.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crypto/src') 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; } -- cgit 1.5.1