summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2018-10-11 20:41:55 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2018-10-11 20:41:55 +0700
commitd4f3d5073fea559403e67ea8992abca9dee72641 (patch)
treebf78b723da1c3800ad951b71593168a696c1842f /crypto
parentAdd missing file entry from previous commit (diff)
downloadBouncyCastle.NET-ed25519-d4f3d5073fea559403e67ea8992abca9dee72641.tar.xz
Port PGP utility fix from Java
Diffstat (limited to '')
-rw-r--r--crypto/src/bcpg/BcpgOutputStream.cs1
-rw-r--r--crypto/src/bcpg/LiteralDataPacket.cs6
-rw-r--r--crypto/src/openpgp/PgpUtilities.cs2
3 files changed, 7 insertions, 2 deletions
diff --git a/crypto/src/bcpg/BcpgOutputStream.cs b/crypto/src/bcpg/BcpgOutputStream.cs
index 7ab661edb..738c28211 100644
--- a/crypto/src/bcpg/BcpgOutputStream.cs
+++ b/crypto/src/bcpg/BcpgOutputStream.cs
@@ -376,6 +376,7 @@ namespace Org.BouncyCastle.Bcpg
             if (partialBuffer != null)
             {
                 PartialFlush(true);
+                Array.Clear(partialBuffer, 0, partialBuffer.Length);
                 partialBuffer = null;
             }
         }
diff --git a/crypto/src/bcpg/LiteralDataPacket.cs b/crypto/src/bcpg/LiteralDataPacket.cs
index 63a2c6d44..b4d28a201 100644
--- a/crypto/src/bcpg/LiteralDataPacket.cs
+++ b/crypto/src/bcpg/LiteralDataPacket.cs
@@ -23,7 +23,11 @@ namespace Org.BouncyCastle.Bcpg
 			fileName = new byte[len];
 			for (int i = 0; i != len; ++i)
             {
-                fileName[i] = (byte)bcpgIn.ReadByte();
+                int ch = bcpgIn.ReadByte();
+                if (ch < 0)
+                    throw new IOException("literal data truncated in header");
+
+                fileName[i] = (byte)ch;
             }
 
 			modDate = (((uint)bcpgIn.ReadByte() << 24)
diff --git a/crypto/src/openpgp/PgpUtilities.cs b/crypto/src/openpgp/PgpUtilities.cs
index a3efd591f..10d1ac398 100644
--- a/crypto/src/openpgp/PgpUtilities.cs
+++ b/crypto/src/openpgp/PgpUtilities.cs
@@ -367,7 +367,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             byte[]		buffer)
         {
             PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
-            Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, buffer);
+            Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, Arrays.Clone(buffer));
 			PipeFileContents(file, pOut, buffer.Length);
         }