From 2ab0470b433806a66c469f70f8db01eb4e76f68a Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Tue, 5 Dec 2017 14:20:30 +0800 Subject: [PATCH] HBASE-19431 The tag array written by IndividualBytesFieldCell#write is out of bounds --- .../hbase/IndividualBytesFieldCell.java | 2 +- .../hbase/TestIndividualBytesFieldCell.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java index 62335539fd3..78ad5783946 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java @@ -155,7 +155,7 @@ public class IndividualBytesFieldCell implements ExtendedCell { out.write((byte)(0xff & getTagsLength())); // Tags byte array - out.write(tags); + out.write(tags, tagsOffset, tagsLength); } return getSerializedSize(withTags); diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java index 49eb2b74df1..0fde1a3409f 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java @@ -239,4 +239,24 @@ public class TestIndividualBytesFieldCell { Bytes.toBytes("value"), 0, 5, Bytes.toBytes("tags"), 0, 100); } + + @Test + public void testWriteTag() throws IOException { + byte[] tags = Bytes.toBytes("---tags---"); + int tagOffset = 3; + int length = 4; + IndividualBytesFieldCell cell + = new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, + Bytes.toBytes("family"), 0, 6, + Bytes.toBytes("qualifier"), 0, 9, + 0L, KeyValue.Type.Put, 0, + Bytes.toBytes("value"), 0, 5, + tags, tagOffset, length); + + try (ByteArrayOutputStream output = new ByteArrayOutputStream(300)) { + cell.write(output, true); + byte[] buf = output.toByteArray(); + assertEquals(cell.getSerializedSize(true), buf.length); + } + } }