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

Reviewed-by: dholmes, alanb
This commit is contained in:
Brian Burkhalter 2023-01-23 17:12:49 +00:00
parent 542bfe61e6
commit a56598f5a5
5 changed files with 218 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -178,14 +178,31 @@ class Direct$Type$Buffer$RW$$BO$
}
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
// The long-valued capacity is restricted to int range.
//
private Direct$Type$Buffer(long addr, int cap) {
super(-1, 0, cap, cap, null);
private Direct$Type$Buffer(long addr, long cap) {
super(-1, 0, checkCapacity(cap), (int)cap, null);
address = addr;
cleaner = null;
att = null;
}
// Throw an IllegalArgumentException if the capacity is not in
// the range [0, Integer.MAX_VALUE]
//
private static int checkCapacity(long capacity) {
if (capacity < 0) {
throw new IllegalArgumentException
("JNI NewDirectByteBuffer passed capacity < 0: ("
+ capacity + ")");
} else if (capacity > Integer.MAX_VALUE) {
throw new IllegalArgumentException
("JNI NewDirectByteBuffer passed capacity > Integer.MAX_VALUE: ("
+ capacity + ")");
}
return (int)capacity;
}
#end[rw]
// For memory-mapped buffers -- invoked by FileChannelImpl via reflection