Skip to content

Commit 7868d58

Browse files
author
gefeili
committed
fix in DefaultMultiBlockCipher
1 parent 07bb6a3 commit 7868d58

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

core/src/main/java/org/bouncycastle/crypto/DefaultMultiBlockCipher.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ public int processBlocks(byte[] in, int inOff, int blockCount, byte[] out, int o
2020

2121
int resultLen = 0;
2222
int blockSize = this.getMultiBlockSize();
23-
23+
int len = blockCount * blockSize;
24+
if (in == out && segmentsOverlap(inOff, len, outOff, len))
25+
{
26+
in = new byte[len];
27+
System.arraycopy(out, inOff, in, 0, len);
28+
inOff = 0;
29+
}
2430
for (int i = 0; i != blockCount; i++)
2531
{
2632
resultLen += this.processBlock(in, inOff, out, outOff + resultLen);
@@ -30,4 +36,10 @@ public int processBlocks(byte[] in, int inOff, int blockCount, byte[] out, int o
3036

3137
return resultLen;
3238
}
39+
40+
protected boolean segmentsOverlap(int inOff, int inLen, int outOff, int outLen)
41+
{
42+
// please ensure a valid check for inLen > 0 and outLen > 0 outside this function
43+
return inOff <= outOff + outLen && outOff <= inOff + inLen;
44+
}
3345
}

0 commit comments

Comments
 (0)