Skip to content

Commit 50e2499

Browse files
arshadmohammadndimiduk
authored andcommitted
HBASE-26856 BufferedDataBlockEncoder.OnheapDecodedCell value can get corrupted
Created OnheapDecodedCell and OffheapDecodedExtendedCell objects with duplicate copy of ByteBuffer's underlying array instead of original ByteBuffer Signed-off-by: Andrew Purtell <apurtell@apache.org> Signed-off-by: Pankaj Kumar<pankajkumar@apache.org>
1 parent ac7622c commit 50e2499

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ private Cell toOnheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
232232
int tOffset = 0;
233233
if (this.includeTags) {
234234
if (this.tagCompressionContext == null) {
235-
tagsArray = valAndTagsBuffer.array();
236235
tOffset =
237236
valAndTagsBuffer.arrayOffset() + vOffset + this.valueLength + tagsLenSerializationSize;
237+
tagsArray = Bytes.copy(valAndTagsBuffer.array(), tOffset, this.tagsLength);
238+
tOffset = 0;
238239
} else {
239240
tagsArray = Bytes.copy(tagsBuffer, 0, this.tagsLength);
240241
tOffset = 0;
@@ -243,9 +244,9 @@ private Cell toOnheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
243244
return new OnheapDecodedCell(Bytes.copy(keyBuffer, 0, this.keyLength),
244245
currentKey.getRowLength(), currentKey.getFamilyOffset(), currentKey.getFamilyLength(),
245246
currentKey.getQualifierOffset(), currentKey.getQualifierLength(), currentKey.getTimestamp(),
246-
currentKey.getTypeByte(), valAndTagsBuffer.array(),
247-
valAndTagsBuffer.arrayOffset() + vOffset, this.valueLength, memstoreTS, tagsArray, tOffset,
248-
this.tagsLength);
247+
currentKey.getTypeByte(), Bytes.copy(valAndTagsBuffer.array(),
248+
valAndTagsBuffer.arrayOffset() + vOffset, this.valueLength),
249+
0, this.valueLength, memstoreTS, tagsArray, tOffset, this.tagsLength);
249250
}
250251

251252
private Cell toOffheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
@@ -254,13 +255,26 @@ private Cell toOffheapCell(ByteBuffer valAndTagsBuffer, int vOffset,
254255
int tOffset = 0;
255256
if (this.includeTags) {
256257
if (this.tagCompressionContext == null) {
257-
tagsBuf = valAndTagsBuffer;
258258
tOffset = vOffset + this.valueLength + tagsLenSerializationSize;
259+
byte[] output = new byte[this.tagsLength];
260+
ByteBufferUtils.copyFromBufferToArray(output, valAndTagsBuffer, tOffset, 0,
261+
this.tagsLength);
262+
tagsBuf = ByteBuffer.wrap(output);
263+
tOffset = 0;
259264
} else {
260265
tagsBuf = ByteBuffer.wrap(Bytes.copy(tagsBuffer, 0, this.tagsLength));
261266
tOffset = 0;
262267
}
263268
}
269+
270+
if (this.valueLength > 0) {
271+
byte[] output = new byte[this.valueLength];
272+
ByteBufferUtils.copyFromBufferToArray(output, valAndTagsBuffer, vOffset, 0,
273+
this.valueLength);
274+
valAndTagsBuffer = ByteBuffer.wrap(output);
275+
vOffset = 0;
276+
}
277+
264278
return new OffheapDecodedExtendedCell(
265279
ByteBuffer.wrap(Bytes.copy(keyBuffer, 0, this.keyLength)), currentKey.getRowLength(),
266280
currentKey.getFamilyOffset(), currentKey.getFamilyLength(), currentKey.getQualifierOffset(),

0 commit comments

Comments
 (0)