-
Bug
-
Resolution: Fixed
-
P4
-
8, 11
-
b04
-
windows
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8243090 | openjdk8u252 | Martin Balao Alonso | P4 | Resolved | Fixed | |
JDK-8237106 | 8u251 | Ivan Gerasimov | P4 | Resolved | Fixed | b02 |
JDK-8239716 | emb-8u251 | Weijun Wang | P4 | Resolved | Fixed | team |
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
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
- backported by
-
JDK-8237106 JNI array not released in libsunmscapi convertToLittleEndian
- Resolved
-
JDK-8239716 JNI array not released in libsunmscapi convertToLittleEndian
- Resolved
-
JDK-8243090 JNI array not released in libsunmscapi convertToLittleEndian
- Resolved