Skip to content

Commit 2619add

Browse files
committed
Fix blocklist violations.
1 parent 66bbc40 commit 2619add

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/Boundaries.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ public static ByteBuffer byteBufferSlice(ByteBuffer buf, int pos, int limit) {
238238
return buf.slice(pos, limit - pos);
239239
}
240240

241+
@TruffleBoundary(allowInlining = true)
242+
public static void byteBufferGet(ByteBuffer src, int srcPos, byte[] dst, int dstPos, int length) {
243+
src.get(srcPos, dst, dstPos, length);
244+
}
245+
241246
@TruffleBoundary(allowInlining = true)
242247
public static void byteBufferPutArray(ByteBuffer dst, int dstPos, byte[] src, int srcPos, int srcLength) {
243248
dst.put(dstPos, src, srcPos, srcLength);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/JSArrayBufferObject.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import java.nio.ByteBuffer;
4444
import java.nio.ByteOrder;
45-
import java.util.Objects;
4645

4746
import com.oracle.truffle.api.dsl.Bind;
4847
import com.oracle.truffle.api.dsl.Cached;
@@ -57,6 +56,7 @@
5756
import com.oracle.truffle.api.object.Shape;
5857
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5958
import com.oracle.truffle.api.strings.TruffleString;
59+
import com.oracle.truffle.js.runtime.Boundaries;
6060
import com.oracle.truffle.js.runtime.Errors;
6161
import com.oracle.truffle.js.runtime.JSAgentWaiterList;
6262
import com.oracle.truffle.js.runtime.JSConfig;
@@ -166,21 +166,28 @@ long getBufferSize() {
166166

167167
private void ensureNotDetached() throws IndexOutOfBoundsException {
168168
if (isDetached()) {
169-
throw DetachedBufferIndexOutOfBoundsException.INSTANCE;
169+
throw BufferIndexOutOfBoundsException.INSTANCE;
170170
}
171171
}
172172

173173
@ExportMessage
174174
void readBuffer(long byteOffset, byte[] destination, int destinationOffset, int length) throws InvalidBufferOffsetException {
175175
try {
176176
ensureNotDetached();
177-
System.arraycopy(byteArray, Objects.checkFromIndexSize(Math.toIntExact(byteOffset), length, byteArray.length),
178-
destination, Objects.checkFromIndexSize(destinationOffset, length, destination.length), length);
177+
System.arraycopy(byteArray, checkFromIndexSize(Math.toIntExact(byteOffset), length, byteArray.length),
178+
destination, checkFromIndexSize(destinationOffset, length, destination.length), length);
179179
} catch (IndexOutOfBoundsException | ArithmeticException e) {
180180
throw InvalidBufferOffsetException.create(byteOffset, length);
181181
}
182182
}
183183

184+
private static int checkFromIndexSize(int fromIndex, int size, int length) {
185+
if ((length | fromIndex | size) < 0 || size > length - fromIndex) {
186+
throw BufferIndexOutOfBoundsException.INSTANCE;
187+
}
188+
return fromIndex;
189+
}
190+
184191
@ExportMessage
185192
byte readBufferByte(long byteOffset) throws InvalidBufferOffsetException {
186193
try {
@@ -345,15 +352,15 @@ final long getBufferSize() {
345352

346353
private void ensureNotDetached() {
347354
if (isDetached()) {
348-
throw DetachedBufferIndexOutOfBoundsException.INSTANCE;
355+
throw BufferIndexOutOfBoundsException.INSTANCE;
349356
}
350357
}
351358

352359
@ExportMessage
353360
final void readBuffer(long byteOffset, byte[] destination, int destinationOffset, int length) throws InvalidBufferOffsetException {
354361
try {
355362
ensureNotDetached();
356-
byteBuffer.get(Math.toIntExact(byteOffset), destination, destinationOffset, length);
363+
Boundaries.byteBufferGet(byteBuffer, Math.toIntExact(byteOffset), destination, destinationOffset, length);
357364
} catch (IndexOutOfBoundsException | ArithmeticException e) {
358365
throw InvalidBufferOffsetException.create(byteOffset, length);
359366
}
@@ -768,10 +775,10 @@ public static JSArrayBufferObject createInteropArrayBuffer(Shape shape, JSDynami
768775
}
769776

770777
@SuppressWarnings("serial")
771-
static final class DetachedBufferIndexOutOfBoundsException extends IndexOutOfBoundsException {
772-
private static final IndexOutOfBoundsException INSTANCE = new DetachedBufferIndexOutOfBoundsException();
778+
static final class BufferIndexOutOfBoundsException extends IndexOutOfBoundsException {
779+
private static final IndexOutOfBoundsException INSTANCE = new BufferIndexOutOfBoundsException();
773780

774-
private DetachedBufferIndexOutOfBoundsException() {
781+
private BufferIndexOutOfBoundsException() {
775782
}
776783

777784
@SuppressWarnings("sync-override")

graal-nodejs/mx.graal-nodejs/com.oracle.truffle.trufflenode/src/com/oracle/truffle/trufflenode/node/ArrayBufferGetContentsNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.truffle.api.nodes.LoopNode;
5353
import com.oracle.truffle.api.nodes.Node;
5454
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
55+
import com.oracle.truffle.js.runtime.Boundaries;
5556
import com.oracle.truffle.js.runtime.Errors;
5657
import com.oracle.truffle.js.runtime.JSConfig;
5758
import com.oracle.truffle.js.runtime.util.DirectByteBufferHelper;
@@ -84,7 +85,7 @@ protected ByteBuffer doInteropBuffer(Object buffer,
8485
int remaining = bufferSize - i;
8586
int copyLength = Math.min(copyBufferSize, remaining);
8687
interop.readBuffer(buffer, i, copyBuffer, 0, copyLength);
87-
byteBuffer.put(i, copyBuffer, 0, copyLength);
88+
Boundaries.byteBufferPutArray(byteBuffer, i, copyBuffer, 0, copyLength);
8889
}
8990
LoopNode.reportLoopCount(this, bufferSize);
9091
return byteBuffer;

0 commit comments

Comments
 (0)