fix bug with handling of more than 256 bytes

This commit is contained in:
Eliot Jones
2022-04-03 15:20:42 -04:00
parent 347259eaa5
commit 3ab0883cf3

View File

@@ -1,6 +1,7 @@
namespace UglyToad.PdfPig.Encryption namespace UglyToad.PdfPig.Encryption
{ {
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
@@ -28,6 +29,11 @@
var buffer = new byte[256]; var buffer = new byte[256];
if (data.Length > 256)
{
Debugger.Break();
}
using (var decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV)) using (var decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV))
using (var input = new MemoryStream(data)) using (var input = new MemoryStream(data))
using (var output = new MemoryStream()) using (var output = new MemoryStream())
@@ -35,15 +41,15 @@
input.Seek(iv.Length, SeekOrigin.Begin); input.Seek(iv.Length, SeekOrigin.Begin);
using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read)) using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
{ {
var offset = 0;
int read; int read;
do do
{ {
read = cryptoStream.Read(buffer, offset, buffer.Length - offset); read = cryptoStream.Read(buffer, 0, buffer.Length);
output.Write(buffer, offset, read); if (read > 0)
{
offset += read; output.Write(buffer, 0, read);
}
} while (read > 0); } while (read > 0);
return output.ToArray(); return output.ToArray();