Make SnappyFramedDecoder more robust against corrupt frame
This commit is contained in:
parent
2ac7983471
commit
36f8630512
@ -46,6 +46,7 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
|
||||
private int chunkLength;
|
||||
private ChunkType chunkType;
|
||||
private boolean started;
|
||||
private boolean corrupted;
|
||||
|
||||
/**
|
||||
* Creates a new snappy-framed decoder with validation of checksums
|
||||
@ -74,6 +75,12 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
|
||||
return;
|
||||
}
|
||||
|
||||
if (corrupted) {
|
||||
in.skipBytes(in.readableBytes());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
while (in.isReadable()) {
|
||||
if (chunkLength == 0) {
|
||||
if (in.readableBytes() < 3) {
|
||||
@ -130,9 +137,9 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
|
||||
throw new CompressionException("Received UNCOMPRESSED_DATA tag before STREAM_IDENTIFIER");
|
||||
}
|
||||
checksum = in.readUnsignedByte()
|
||||
| (in.readUnsignedByte() << 8)
|
||||
| (in.readUnsignedByte() << 16)
|
||||
| (in.readUnsignedByte() << 24);
|
||||
| in.readUnsignedByte() << 8
|
||||
| in.readUnsignedByte() << 16
|
||||
| in.readUnsignedByte() << 24;
|
||||
if (validateChecksums) {
|
||||
ByteBuf data = in.readBytes(chunkLength);
|
||||
validateChecksum(data, checksum);
|
||||
@ -146,9 +153,9 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
|
||||
throw new CompressionException("Received COMPRESSED_DATA tag before STREAM_IDENTIFIER");
|
||||
}
|
||||
checksum = in.readUnsignedByte()
|
||||
| (in.readUnsignedByte() << 8)
|
||||
| (in.readUnsignedByte() << 16)
|
||||
| (in.readUnsignedByte() << 24);
|
||||
| in.readUnsignedByte() << 8
|
||||
| in.readUnsignedByte() << 16
|
||||
| in.readUnsignedByte() << 24;
|
||||
if (validateChecksums) {
|
||||
ByteBuf uncompressed = ctx.alloc().buffer();
|
||||
snappy.decode(in, uncompressed, chunkLength);
|
||||
@ -162,6 +169,10 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
|
||||
|
||||
chunkLength = 0;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
corrupted = true;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user