RFR: 8299684: (bf) JNI direct buffer functions with large capacity behave unexpectedly

Paul Sandoz psandoz at openjdk.org
Thu Jan 5 23:25:50 UTC 2023


On Thu, 5 Jan 2023 22:25:19 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Remove cast in `JNI::NewDirectByteBuffer`of `long` capacity to `int`, modify the constructor in question to accept a `long` capacity, and verify in the constructor that the  capacity does not overflow `int` range, throwing IAE If it does.

Requires an update to the JNI spec and therefore a CSR?

src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 249:

> 247:             return Math.toIntExact(capacity);
> 248:         } catch (ArithmeticException ignore) {
> 249:             throw new IllegalArgumentException("capacity " + capacity

I think we should mention the source, that the capacity value originates from a native call to NewDirectByteBuffer, since that will not appear in any frames of the reported stack trace.

-------------

PR: https://git.openjdk.org/jdk/pull/11873


More information about the nio-dev mailing list