From d9315fa04311f0c9d857731226bf640b4212f814 Mon Sep 17 00:00:00 2001 From: Istvan Toth Date: Mon, 6 Dec 2021 16:56:00 +0100 Subject: [PATCH] HBASE-26527 ArrayIndexOutOfBoundsException in KeyValueUtil.copyToNewKeyValue() (#3904) Signed-off-by: Andrew Purtell Signed-off-by: Duo Zhang --- .../src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 6b26dea0207..a2fdcc4e6d8 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -128,7 +128,11 @@ public class KeyValueUtil { } public static byte[] copyToNewByteArray(final Cell cell) { - int v1Length = cell.getSerializedSize(); + //Cell#getSerializedSize returns the serialized size of the Source cell, which may + //not serialize all fields. We are constructing a KeyValue backing array here, + //which does include all fields, and must allocate accordingly. + int v1Length = length(cell.getRowLength(), cell.getFamilyLength(), + cell.getQualifierLength(), cell.getValueLength(), cell.getTagsLength(), true); byte[] backingBytes = new byte[v1Length]; appendToByteArray(cell, backingBytes, 0, true); return backingBytes;