Take padded bytes into account when decrypting a stream of data.

Fixes #11573
This commit is contained in:
Fumiaki Yoshimatsu
2021-09-14 17:31:41 -04:00
committed by Cody Henthorne
parent cc99febe32
commit e18d9e665f
2 changed files with 44 additions and 2 deletions
@@ -162,10 +162,12 @@ public class AttachmentCipherInputStream extends FilterInputStream {
private int readFinal(byte[] buffer, int offset, int length) throws IOException {
try {
int flourish = cipher.doFinal(buffer, offset);
byte[] internal = new byte[buffer.length];
int actualLength = Math.min(length, cipher.doFinal(internal, 0));
System.arraycopy(internal, 0, buffer, offset, actualLength);
done = true;
return flourish;
return actualLength;
} catch (IllegalBlockSizeException | BadPaddingException | ShortBufferException e) {
throw new IOException(e);
}