bc-java icon indicating copy to clipboard operation
bc-java copied to clipboard

Caused by: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 32 out of bounds for byte[31]

Open ankgupta067 opened this issue 7 months ago • 1 comments

we are intermittently facing this issue in org.bouncycastle:bcutil-jdk18on:1.80 version , this issue comes intermittently in 1 out of 100 requests and also doesnt happen on retry of that http request , i want to undesrtand how to fix this issue , below is the stack trace

Caused by: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 32 out of bounds for byte[31] at java.base/java.lang.System.arraycopy(Native Method) at org.spongycastle.crypto.params.X25519PublicKeyParameters.<init>(Unknown Source) at org.spongycastle.jcajce.provider.asymmetric.edec.KeyAgreementSpi.engineDoPhase(KeyAgreementSpi.java:163) at java.base/javax.crypto.KeyAgreement.doPhase(KeyAgreement.java:581) at java.base/sun.security.ssl.KAKeyDerivation.t12DeriveKey(KAKeyDerivation.java:75) at java.base/sun.security.ssl.KAKeyDerivation.deriveKey(KAKeyDerivation.java:61) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720) at com.sfdc.industries.clm.pdfconversion.client.ExternalApiClient$$SpringCGLIB$$0.post(<generated>) at com.sfdc.industries.clm.pdfconversion.service.OutboundCommunicationService.updateDocumentGenerationResult(OutboundCommunicationService.java:297) at com.sfdc.industries.clm.pdfconversion.service.OutboundCommunicationService.updateDocGenerationResultSuccess(OutboundCommunicationService.java:260) at com.sfdc.industries.clm.pdfconversion.messaging.PdfConversionKafkaListener.processMessage(PdfConversionKafkaListener.java:241) at com.sfdc.industries.clm.pdfconversion.messaging.PdfConversionKafkaListener.listen(PdfConversionKafkaListener.java:84) at jdk.internal.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169) at org.springframework.kafka.listener.adapter.KotlinAwareInvocableHandlerMethod.doInvoke(KotlinAwareInvocableHandlerMethod.java:45) ) 27-05-2025 15:07:29.419 [pc-pool-6-thread-4 ] 411e5296c6a62f1e 00DXH0000000UFp 0nnXH0000001d8FYAQ [ERROR] ExternalApiClient - Failed with IOException while making http call to UpdateDocumentGenerationResult, ExceptionRootCause: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 32 out of bounds for byte[31]. ExceptionStackTrace: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:578) at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:123) at com.sfdc.industries.clm.pdfconversion.client.ExternalApiClient.makeHttpCall(ExternalApiClient.java:94) at com.sfdc.industries.clm.pdfconversion.client.ExternalApiClient.post(ExternalApiClient.java:82) at jdk.internal.reflect.GeneratedMethodAccessor52.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768) at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:114) at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:357) at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:246) at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:135) at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:162) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)

ankgupta067 avatar Jun 02 '25 06:06 ankgupta067

Please clarify what BC jars you are using. The problematic part of the stack trace shows:

org.spongycastle.crypto.params.X25519PublicKeyParameters. org.spongycastle.jcajce.provider.asymmetric.edec.KeyAgreementSpi.engineDoPhase

Obviously the package is spongycastle and not bouncycastle, so where are these classes coming from?

You reference org.bouncycastle:bcutil-jdk18on:1.80, which is a jar that you might use with org.bouncycastle:bcprov-jdk18on:1.80 - and the bcprov jar is the place I'd expect to find e.g. org.bouncycastle.jcajce.provider.asymmetric.edec.KeyAgreementSpi (but not spongycastle).

Perhaps you just need to remove some old spongycastle jars and install the latest BC ones.

peterdettman avatar Jun 02 '25 14:06 peterdettman

Does not appear to be a BC bug (or at least a current BC bug).

dghgit avatar Aug 11 '25 04:08 dghgit