Fixed issues with array offsets when using unpooled buffers.
This commit is contained in:
parent
5e8e475747
commit
627ef245d2
|
@ -41,6 +41,7 @@ import net.jpountz.lz4.LZ4FastDecompressor;
|
||||||
/**
|
/**
|
||||||
* Nothing in this class is thread safe
|
* Nothing in this class is thread safe
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
public
|
public
|
||||||
class KryoExtra<C extends CryptoConnection> extends Kryo {
|
class KryoExtra<C extends CryptoConnection> extends Kryo {
|
||||||
// snappycomp : 7.534 micros/op; 518.5 MB/s (output: 55.1%)
|
// snappycomp : 7.534 micros/op; 518.5 MB/s (output: 55.1%)
|
||||||
|
@ -257,7 +258,7 @@ class KryoExtra<C extends CryptoConnection> extends Kryo {
|
||||||
// we can use it...
|
// we can use it...
|
||||||
inputArray = inputBuf.array();
|
inputArray = inputBuf.array();
|
||||||
inputArrayLength = -1; // this is so we don't REUSE this array accidentally!
|
inputArrayLength = -1; // this is so we don't REUSE this array accidentally!
|
||||||
inputOffset = inputBuf.arrayOffset();
|
inputOffset = inputBuf.arrayOffset() + lengthLength;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// we can NOT use it.
|
// we can NOT use it.
|
||||||
|
@ -290,7 +291,7 @@ class KryoExtra<C extends CryptoConnection> extends Kryo {
|
||||||
}
|
}
|
||||||
inputBuf = decompressBuf;
|
inputBuf = decompressBuf;
|
||||||
|
|
||||||
// LZ4 decompress, requires the size of the ORIGINAL length (because we use the FAST decompressor
|
// LZ4 decompress, requires the size of the ORIGINAL length (because we use the FAST decompressor)
|
||||||
decompressor.decompress(inputArray, inputOffset, decompressOutputArray, 0, uncompressedLength);
|
decompressor.decompress(inputArray, inputOffset, decompressOutputArray, 0, uncompressedLength);
|
||||||
|
|
||||||
inputBuf.setIndex(0, uncompressedLength);
|
inputBuf.setIndex(0, uncompressedLength);
|
||||||
|
@ -450,10 +451,11 @@ class KryoExtra<C extends CryptoConnection> extends Kryo {
|
||||||
ByteBuf inputBuf = buffer;
|
ByteBuf inputBuf = buffer;
|
||||||
|
|
||||||
final long gcmIVCounter = OptimizeUtilsByteBuf.readLong(buffer, true);
|
final long gcmIVCounter = OptimizeUtilsByteBuf.readLong(buffer, true);
|
||||||
|
int lengthLength = OptimizeUtilsByteArray.longLength(gcmIVCounter, true);
|
||||||
|
|
||||||
|
|
||||||
// have to adjust for the gcmIVCounter
|
// have to adjust for the gcmIVCounter
|
||||||
length = length - OptimizeUtilsByteArray.longLength(gcmIVCounter, true);
|
length = length - lengthLength;
|
||||||
|
|
||||||
|
|
||||||
/////////// decrypting data
|
/////////// decrypting data
|
||||||
|
@ -476,7 +478,7 @@ class KryoExtra<C extends CryptoConnection> extends Kryo {
|
||||||
// we can use it...
|
// we can use it...
|
||||||
inputArray = inputBuf.array();
|
inputArray = inputBuf.array();
|
||||||
inputArrayLength = -1; // this is so we don't REUSE this array accidentally!
|
inputArrayLength = -1; // this is so we don't REUSE this array accidentally!
|
||||||
inputOffset = inputBuf.arrayOffset();
|
inputOffset = inputBuf.arrayOffset() + lengthLength;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// we can NOT use it.
|
// we can NOT use it.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user