@@ -1296,6 +1296,7 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
12961296 int ret = BAD_FUNC_ARG ;
12971297 int maxInputSz ;
12981298 int inSz = length ;
1299+ int arrayOffset = 0 ;
12991300 byte * data = NULL ;
13001301 WOLFSSL * ssl = (WOLFSSL * )(uintptr_t )sslPtr ;
13011302 jbyteArray bufArr = NULL ;
@@ -1326,6 +1327,15 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
13261327 return SSL_FAILURE ;
13271328 }
13281329
1330+ /* Honor arrayOffset() for sliced/duplicated array-backed
1331+ * ByteBuffers, where logical position 0 maps to backing
1332+ * array index arrayOffset() */
1333+ arrayOffset = (int )(* jenv )-> CallIntMethod (jenv , buf ,
1334+ g_bufferArrayOffsetMethodId );
1335+ if ((* jenv )-> ExceptionCheck (jenv )) {
1336+ return SSL_FAILURE ;
1337+ }
1338+
13291339 /* Get array elements */
13301340 data = (byte * )(* jenv )-> GetByteArrayElements (jenv , bufArr , NULL );
13311341 if (data == NULL ) {
@@ -1349,8 +1359,8 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
13491359 }
13501360 }
13511361
1352- ret = SSLWriteNonblockingWithSelectPoll (ssl , data + position ,
1353- (int )inSz , (int )timeout );
1362+ ret = SSLWriteNonblockingWithSelectPoll (ssl ,
1363+ data + arrayOffset + position , (int )inSz , (int )timeout );
13541364
13551365 /* release memory if using array mode */
13561366 if (hasArray ) {
@@ -1520,6 +1530,7 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15201530 int size = 0 ;
15211531 int maxOutputSz ;
15221532 int outSz = length ;
1533+ int arrayOffset = 0 ;
15231534 byte * data = NULL ;
15241535 WOLFSSL * ssl = (WOLFSSL * )(uintptr_t )sslPtr ;
15251536 jbyteArray bufArr = NULL ;
@@ -1550,6 +1561,15 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15501561 return SSL_FAILURE ;
15511562 }
15521563
1564+ /* Honor arrayOffset() for sliced/duplicated array-backed
1565+ * ByteBuffers, where logical position 0 maps to backing
1566+ * array index arrayOffset() */
1567+ arrayOffset = (int )(* jenv )-> CallIntMethod (jenv , buf ,
1568+ g_bufferArrayOffsetMethodId );
1569+ if ((* jenv )-> ExceptionCheck (jenv )) {
1570+ return SSL_FAILURE ;
1571+ }
1572+
15531573 /* Get array elements */
15541574 data = (byte * )(* jenv )-> GetByteArrayElements (jenv , bufArr , NULL );
15551575 if (data == NULL ) {
@@ -1573,8 +1593,8 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15731593 }
15741594 }
15751595
1576- size = SSLReadNonblockingWithSelectPoll (ssl , data + position ,
1577- outSz , (int )timeout );
1596+ size = SSLReadNonblockingWithSelectPoll (ssl ,
1597+ data + arrayOffset + position , outSz , (int )timeout );
15781598
15791599 /* Release array elements if using array-backed buffer.
15801600 * Note: DirectByteBuffer doesn't need releasing data */
0 commit comments