@@ -1303,6 +1303,7 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
13031303 int ret = BAD_FUNC_ARG ;
13041304 int maxInputSz ;
13051305 int inSz = length ;
1306+ int arrayOffset = 0 ;
13061307 byte * data = NULL ;
13071308 WOLFSSL * ssl = (WOLFSSL * )(uintptr_t )sslPtr ;
13081309 jbyteArray bufArr = NULL ;
@@ -1333,6 +1334,15 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
13331334 return SSL_FAILURE ;
13341335 }
13351336
1337+ /* Honor arrayOffset() for sliced/duplicated array-backed
1338+ * ByteBuffers, where logical position 0 maps to backing
1339+ * array index arrayOffset() */
1340+ arrayOffset = (int )(* jenv )-> CallIntMethod (jenv , buf ,
1341+ g_bufferArrayOffsetMethodId );
1342+ if ((* jenv )-> ExceptionCheck (jenv )) {
1343+ return SSL_FAILURE ;
1344+ }
1345+
13361346 /* Get array elements */
13371347 data = (byte * )(* jenv )-> GetByteArrayElements (jenv , bufArr , NULL );
13381348 if (data == NULL ) {
@@ -1356,8 +1366,8 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_write__JLjava_nio_ByteBuf
13561366 }
13571367 }
13581368
1359- ret = SSLWriteNonblockingWithSelectPoll (ssl , data + position ,
1360- (int )inSz , (int )timeout );
1369+ ret = SSLWriteNonblockingWithSelectPoll (ssl ,
1370+ data + arrayOffset + position , (int )inSz , (int )timeout );
13611371
13621372 /* release memory if using array mode */
13631373 if (hasArray ) {
@@ -1530,6 +1540,7 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15301540 int size = 0 ;
15311541 int maxOutputSz ;
15321542 int outSz = length ;
1543+ int arrayOffset = 0 ;
15331544 byte * data = NULL ;
15341545 WOLFSSL * ssl = (WOLFSSL * )(uintptr_t )sslPtr ;
15351546 jbyteArray bufArr = NULL ;
@@ -1560,6 +1571,15 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15601571 return SSL_FAILURE ;
15611572 }
15621573
1574+ /* Honor arrayOffset() for sliced/duplicated array-backed
1575+ * ByteBuffers, where logical position 0 maps to backing
1576+ * array index arrayOffset() */
1577+ arrayOffset = (int )(* jenv )-> CallIntMethod (jenv , buf ,
1578+ g_bufferArrayOffsetMethodId );
1579+ if ((* jenv )-> ExceptionCheck (jenv )) {
1580+ return SSL_FAILURE ;
1581+ }
1582+
15631583 /* Get array elements */
15641584 data = (byte * )(* jenv )-> GetByteArrayElements (jenv , bufArr , NULL );
15651585 if (data == NULL ) {
@@ -1583,8 +1603,8 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_read__JLjava_nio_ByteBuff
15831603 }
15841604 }
15851605
1586- size = SSLReadNonblockingWithSelectPoll (ssl , data + position ,
1587- outSz , (int )timeout );
1606+ size = SSLReadNonblockingWithSelectPoll (ssl ,
1607+ data + arrayOffset + position , outSz , (int )timeout );
15881608
15891609 /* Release array elements if using array-backed buffer.
15901610 * Note: DirectByteBuffer doesn't need releasing data */
0 commit comments