HBASE-26527 ArrayIndexOutOfBoundsException in KeyValueUtil.copyToNewKeyValue() (#3904)

Signed-off-by: Andrew Purtell <apurtell@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Istvan Toth 2021-12-06 16:56:00 +01:00 committed by GitHub
parent 9cf224d4fe
commit d9315fa043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -128,7 +128,11 @@ public class KeyValueUtil {
} }
public static byte[] copyToNewByteArray(final Cell cell) { 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]; byte[] backingBytes = new byte[v1Length];
appendToByteArray(cell, backingBytes, 0, true); appendToByteArray(cell, backingBytes, 0, true);
return backingBytes; return backingBytes;