Skip to content

Commit 67fb4d8

Browse files
author
gefeili
committed
Fix #2035 issue in AEADBaseEngine.
1 parent 8954c62 commit 67fb4d8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/AEADBaseEngine.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,22 @@ protected int processEncDecBytes(byte[] input, int inOff, int len, byte[] output
733733
m_bufPos += len;
734734
return 0;
735735
}
736-
resultLength = processor.getUpdateOutputSize(len) + m_bufPos - (forEncryption ? 0 : MAC_SIZE);
736+
int length = processor.getUpdateOutputSize(len);
737+
resultLength = length + m_bufPos - (forEncryption ? 0 : MAC_SIZE);
737738
ensureSufficientOutputBuffer(output, outOff, resultLength - resultLength % BlockSize);
738739
resultLength = 0;
740+
if (input == output)
741+
{
742+
int inEnd = inOff + len;
743+
int outEnd = outOff + length;
744+
if ((inOff <= outOff && outOff <= inEnd) ||
745+
(outOff <= inOff && inOff <= outEnd))
746+
{
747+
input = new byte[len];
748+
System.arraycopy(output, inOff, input, 0, len);
749+
inOff = 0;
750+
}
751+
}
739752
if (forEncryption)
740753
{
741754
if (m_bufPos > 0)
@@ -746,6 +759,7 @@ protected int processEncDecBytes(byte[] input, int inOff, int len, byte[] output
746759
processBufferEncrypt(m_buf, 0, output, outOff);
747760
resultLength = BlockSize;
748761
}
762+
749763
// The function is just an operator >= or >
750764
while (processor.isLengthExceedingBlockSize(len, BlockSize))
751765
{

0 commit comments

Comments
 (0)