From 8e01af6321d727693c4f43344d70b72f2bd10324 Mon Sep 17 00:00:00 2001 From: oliviarla Date: Wed, 26 Aug 2026 17:53:15 +0900 Subject: [PATCH] FIX: Verify correct byte length and not expose origin data object in BKey --- src/main/java/net/spy/memcached/v2/vo/BKey.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/spy/memcached/v2/vo/BKey.java b/src/main/java/net/spy/memcached/v2/vo/BKey.java index db79cdba6..09290849e 100644 --- a/src/main/java/net/spy/memcached/v2/vo/BKey.java +++ b/src/main/java/net/spy/memcached/v2/vo/BKey.java @@ -29,9 +29,9 @@ private BKey(byte[] data) { throw new IllegalArgumentException("BKey byte array cannot be null."); } - if (data.length > 31) { + if (data.length < 1 || data.length > 31) { throw new IllegalArgumentException( - "BKey byte array size must be between 0 and 31. Given size: " + data.length); + "BKey byte array size must be between 1 and 31. Given size: " + data.length); } this.type = BKeyType.BYTE_ARRAY; @@ -62,7 +62,7 @@ public BKeyObject toBKeyObject() { if (this.type == BKeyType.LONG) { return new BKeyObject((Long) this.data); } - return new BKeyObject((byte[]) this.data); + return new BKeyObject(Arrays.copyOf((byte[]) this.data, ((byte[]) this.data).length)); } public static BKey of(BKeyObject bkeyObject) {