-
Bug
-
Resolution: Fixed
-
P3
-
None
-
b08
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8305495 | 17.0.8-oracle | Sean Coffey | P3 | Resolved | Fixed | b01 |
JDK-8303205 | 17.0.7 | Dukebot | P3 | Resolved | Fixed | b04 |
JDK-8303957 | 11.0.20 | Scott Gibbons | P3 | Resolved | Fixed | b01 |
It used to be this [1]:
if (getMode() != GCM_MODE || outputCapacity < estOutSize) {
// create temporary output buffer if the estimated size is larger
// than the user-provided buffer.
internalOutput = new byte[estOutSize];
offset = 0;
}
The assumption in the original issue was, that only GCM would benefit from working on the original buffer. However, the temporary internal buffer can be avoided altogether if the output buffer is large enough.
Furthermore, the need to copy the results back from the temporary buffer to the output buffer can be circumvented.
The current implementation will _always_ create a temporary buffer, despite the output buffer being sufficient. For every call to `Cipher.doFinal(ByteBuffer, ByteBuffer)` this causes the allocation of a byte[] with the size depending on the supplied ciphertext.
A small test program for showing these allocations is available on [2].
[1] https://github.com/openjdk/jdk/blame/e546ae27ffc6c19ae078a41ab6e1741a104958c1/src/java.base/share/classes/com/sun/crypto/provider/CipherCore.java#L946-L951
[2] https://gist.github.com/overheadhunter/f3969950c0fdbaecaa77c857b2246cc5
- backported by
-
JDK-8303205 CipherCore.doFinal(...) causes potentially massive byte[] allocations during decryption
- Resolved
-
JDK-8303957 CipherCore.doFinal(...) causes potentially massive byte[] allocations during decryption
- Resolved
-
JDK-8305495 CipherCore.doFinal(...) causes potentially massive byte[] allocations during decryption
- Resolved
- relates to
-
JDK-8253821 Improve ByteBuffer performance with GCM
- Resolved
-
JDK-8255557 Decouple GCM from CipherCore
- Resolved
- links to
-
Commit openjdk/jdk11u-dev/479ddb6e
-
Commit openjdk/jdk17u-dev/9c35d599
-
Commit openjdk/jdk/409382ba
-
Review openjdk/jdk11u-dev/1780
-
Review openjdk/jdk17u-dev/1169
-
Review openjdk/jdk/7230