From 953e6405746463d0b23215d153432bcad6fff3a3 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sat, 26 Sep 2020 23:47:41 -0700 Subject: [PATCH] java: Use allocateDirect instead of wrap in copy_code This is important, because wrap would use the underlying returned buffer, while the EVMC interface specifically states it must be copied. --- bindings/java/java/src/main/java/org/ethereum/evmc/Host.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java b/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java index 3818e54c2..21a5df080 100644 --- a/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java +++ b/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java @@ -79,10 +79,10 @@ static ByteBuffer copy_code(int context_index, byte[] address, int code_offset) if (code != null && code_offset > 0 && code_offset < code.length) { int length = code.length - code_offset; - return ByteBuffer.wrap(code, 0, length); + return ByteBuffer.allocateDirect(length).put(code, code_offset, length); } - return ByteBuffer.wrap(new byte[0]); + return ByteBuffer.allocateDirect(0); } /** Selfdestruct callback function. */