Skip to content

Fix IndexOutOfBoundsException when calling PostRequest.getUpstreamHeaders#326

Open
MariaLapovska wants to merge 1 commit intoapache:mainfrom
MariaLapovska:fix/index-outofbounds-error
Open

Fix IndexOutOfBoundsException when calling PostRequest.getUpstreamHeaders#326
MariaLapovska wants to merge 1 commit intoapache:mainfrom
MariaLapovska:fix/index-outofbounds-error

Conversation

@MariaLapovska
Copy link

Please answer these questions before submitting a pull request


Bugfix

  • Description
    Currently, if you try to call PostRequest.getUpstreamHeaders() in postFilter(), it intermittently throws IndexOutOfBoundsException (specifically headersLength() method in Req class):
java.lang.IndexOutOfBoundsException: null
        at java.base/java.nio.Buffer$1.apply(Buffer.java:757) ~[na:na]
        at java.base/java.nio.Buffer$1.apply(Buffer.java:754) ~[na:na]
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213) ~[na:na]
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210) ~[na:na]
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98) ~[na:na]
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106) ~[na:na]
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302) ~[na:na]
        at java.base/java.nio.Buffer.checkIndex(Buffer.java:779) ~[na:na]
        at java.base/java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:761) ~[na:na]
        at com.google.flatbuffers.Table.__vector_len(Table.java:125) ~[flatbuffers-java-2.0.0.jar!/:na]
        at io.github.api7.A6.HTTPRespCall.Req.headersLength(Req.java:22) ~[A6-0.6.0-RELEASE.jar!/:na]
        at org.apache.apisix.plugin.runner.PostRequest.getUpstreamHeaders(PostRequest.java:82) ~[apisix-runner-plugin-sdk-0.6.0.jar!/:0.6.0]
        at gg.lita.arch.gateway.plugin.filters.LitaLoginResponseFilter.getPostRequestHeaders(LitaLoginResponseFilter.java:52) ~[!/:0.0.1]
  • How to fix?
    If we follow the same pattern as RpcHandler does with HttpRequest, where it pre-reads the headers, we avoid the given issue, where by the time PostRequest.getUpstreamHeaders() is called from inside one of the plugins, the ByteBuffer could be corrupted, reused, or have a wrong position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments