diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-07-09 16:01:13 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-07-09 16:01:13 +0700 |
commit | 15a3707279e841a240e51364881886c0d0b15767 (patch) | |
tree | 651ba689ab41bd32336fcb8a61a1caa26137bc51 /crypto | |
parent | Add Ed25519 and Ed448 from RFC 8032 (diff) | |
download | BouncyCastle.NET-ed25519-15a3707279e841a240e51364881886c0d0b15767.tar.xz |
Clear buffer after literal data copy
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/openpgp/PgpUtilities.cs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/crypto/src/openpgp/PgpUtilities.cs b/crypto/src/openpgp/PgpUtilities.cs index 7d96dee8d..a3efd591f 100644 --- a/crypto/src/openpgp/PgpUtilities.cs +++ b/crypto/src/openpgp/PgpUtilities.cs @@ -356,7 +356,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(); Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime); - PipeFileContents(file, pOut, 4096); + PipeFileContents(file, pOut, 32768); } /// <summary>Write out the passed in file as a literal data packet in partial packet format.</summary> @@ -376,15 +376,22 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp FileStream inputStream = file.OpenRead(); byte[] buf = new byte[bufSize]; - int len; - while ((len = inputStream.Read(buf, 0, buf.Length)) > 0) + try { - pOut.Write(buf, 0, len); + int len; + while ((len = inputStream.Read(buf, 0, buf.Length)) > 0) + { + pOut.Write(buf, 0, len); + } } + finally + { + Array.Clear(buf, 0, buf.Length); - Platform.Dispose(pOut); - Platform.Dispose(inputStream); - } + Platform.Dispose(pOut); + Platform.Dispose(inputStream); + } + } #endif private const int ReadAhead = 60; |