JDK-8193262 : JNI array not released in libsunmscapi convertToLittleEndian
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Affected Version: 8,11
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2017-12-08
  • Updated: 2021-02-03
  • Resolved: 2018-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 8 Other
11 b04Fixed 8u251Fixed openjdk8u252Fixed
Description
The function convertToLittleEndian [1] may leave scope (line 1822)  without JNI releasing array elements. This could impact GC efficiency. 

1804 * Convert an array in big-endian byte order into little-endian byte order.
1805 */
1806int convertToLittleEndian(JNIEnv *env, jbyteArray source, jbyte* destination,
1807    int destinationLength) {
1808
1809    int sourceLength = env->GetArrayLength(source);
1810
1811    jbyte* sourceBytes = env->GetByteArrayElements(source, 0);
1812    if (sourceBytes == NULL) {
1813        return -1;
1814    }
1815
1816    int copyLen = sourceLength;
1817    if (sourceLength > destinationLength) {
1818        // source might include an extra sign byte
1819        if (sourceLength == destinationLength + 1 && sourceBytes[0] == 0) {
1820            copyLen--;
1821        } else {
==> 1822            return -1;
1823        }
1824    }
1825
1826    // Copy bytes from the end of the source array to the beginning of the
1827    // destination array (until the destination array is full).
1828    // This ensures that the sign byte from the source array will be excluded.
1829    for (int i = 0; i < copyLen; i++) {
1830        destination[i] = sourceBytes[sourceLength - 1 - i];
1831    }
1832    if (copyLen < destinationLength) {
1833        memset(destination + copyLen, 0, destinationLength - copyLen);
1834    }
1835
1836    env->ReleaseByteArrayElements(source, sourceBytes, JNI_ABORT);
1837
1838    return destinationLength;
1839}
1840

[1] http://hg.openjdk.java.net/jdk/jdk/file/71c04702a3d5/src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp#l1822