HBASE-19484 The value array written by ExtendedCell#write is out of bounds

This commit is contained in:
Chia-Ping Tsai 2017-12-11 09:10:14 +08:00
parent 7506591a20
commit 08d6b55750
2 changed files with 21 additions and 1 deletions

View File

@ -54,7 +54,7 @@ public interface ExtendedCell extends RawCell, HeapSize, Cloneable {
PrivateCellUtil.writeFlatKey(this, out);
// Value
out.write(getValueArray());
out.write(getValueArray(), getValueOffset(), getValueLength());
// Tags length and tags byte array
if (withTags && getTagsLength() > 0) {

View File

@ -252,4 +252,24 @@ public class TestIndividualBytesFieldCell {
assertEquals(cell.getSerializedSize(true), buf.length);
}
}
@Test
public void testWriteValue() throws IOException {
byte[] value = Bytes.toBytes("---value---");
int valueOffset = 3;
int valueLength = 5;
IndividualBytesFieldCell cell
= new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3,
Bytes.toBytes("family"), 0, 6,
Bytes.toBytes("qualifier"), 0, 9,
0L, KeyValue.Type.Put, 0,
value, valueOffset, valueLength,
Bytes.toBytes("value"), 0, 5);
try (ByteArrayOutputStream output = new ByteArrayOutputStream(300)) {
cell.write(output, true);
byte[] buf = output.toByteArray();
assertEquals(cell.getSerializedSize(true), buf.length);
}
}
}