Skip to content

Commit 15a3707

Browse files
committed
Clear buffer after literal data copy
1 parent 5268ce4 commit 15a3707

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

crypto/src/openpgp/PgpUtilities.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public static void WriteFileToLiteralData(
356356
{
357357
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
358358
Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime);
359-
PipeFileContents(file, pOut, 4096);
359+
PipeFileContents(file, pOut, 32768);
360360
}
361361

362362
/// <summary>Write out the passed in file as a literal data packet in partial packet format.</summary>
@@ -376,15 +376,22 @@ private static void PipeFileContents(FileInfo file, Stream pOut, int bufSize)
376376
FileStream inputStream = file.OpenRead();
377377
byte[] buf = new byte[bufSize];
378378

379-
int len;
380-
while ((len = inputStream.Read(buf, 0, buf.Length)) > 0)
379+
try
381380
{
382-
pOut.Write(buf, 0, len);
381+
int len;
382+
while ((len = inputStream.Read(buf, 0, buf.Length)) > 0)
383+
{
384+
pOut.Write(buf, 0, len);
385+
}
383386
}
387+
finally
388+
{
389+
Array.Clear(buf, 0, buf.Length);
384390

385-
Platform.Dispose(pOut);
386-
Platform.Dispose(inputStream);
387-
}
391+
Platform.Dispose(pOut);
392+
Platform.Dispose(inputStream);
393+
}
394+
}
388395
#endif
389396

390397
private const int ReadAhead = 60;

0 commit comments

Comments
 (0)