### Question:
Snappy { public void decode(ByteBuf in, ByteBuf out) { while (in.isReadable()) { switch (state) { case READY: state = State.READING_PREAMBLE; case READING_PREAMBLE: int uncompressedLength = readPreamble(in); if (uncompressedLength == PREAMBLE_NOT_FULL) { return; } if (uncompressedLength == 0) { state = State.READY; return; } out.ensureWritable(uncompressedLength); state = State.READING_TAG; case READING_TAG: if (!in.isReadable()) { return; } tag = in.readByte(); switch (tag & 0x03) { case LITERAL: state = State.READING_LITERAL; break; case COPY_1_BYTE_OFFSET: case COPY_2_BYTE_OFFSET: case COPY_4_BYTE_OFFSET: state = State.READING_COPY; break; } break; case READING_LITERAL: int literalWritten = decodeLiteral(tag, in, out); if (literalWritten != NOT_ENOUGH_INPUT) { state = State.READING_TAG; written += literalWritten; } else { return; } break; case READING_COPY: int decodeWritten; switch (tag & 0x03) { case COPY_1_BYTE_OFFSET: decodeWritten = decodeCopyWith1ByteOffset(tag, in, out, written); if (decodeWritten != NOT_ENOUGH_INPUT) { state = State.READING_TAG; written += decodeWritten; } else { return; } break; case COPY_2_BYTE_OFFSET: decodeWritten = decodeCopyWith2ByteOffset(tag, in, out, written); if (decodeWritten != NOT_ENOUGH_INPUT) { state = State.READING_TAG; written += decodeWritten; } else { return; } break; case COPY_4_BYTE_OFFSET: decodeWritten = decodeCopyWith4ByteOffset(tag, in, out, written); if (decodeWritten != NOT_ENOUGH_INPUT) { state = State.READING_TAG; written += decodeWritten; } else { return; } break; } } } }  void reset(); void encode(ByteBuf in, ByteBuf out, int length); void decode(ByteBuf in, ByteBuf out); static int calculateChecksum(ByteBuf data); static int calculateChecksum(ByteBuf data, int offset, int length);  }### Answer:
@Test(expected = DecompressionException.class) public void testDecodeCopyWithTinyOffset() throws Exception { ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 0x0b, 0x04 << 2, 0x6e, 0x65, 0x74, 0x74, 0x79, 0x05 << 2 | 0x01, 0x00 }); ByteBuf out = Unpooled.buffer(10); snappy.decode(in, out); }
@Test(expected = DecompressionException.class) public void testDecodeCopyWithOffsetBeforeChunk() throws Exception { ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 0x0a, 0x04 << 2, 0x6e, 0x65, 0x74, 0x74, 0x79, 0x05 << 2 | 0x01, 0x0b }); ByteBuf out = Unpooled.buffer(10); snappy.decode(in, out); }
@Test(expected = DecompressionException.class) public void testDecodeWithOverlyLongPreamble() throws Exception { ByteBuf in = Unpooled.wrappedBuffer(new byte[] { -0x80, -0x80, -0x80, -0x80, 0x7f, 0x04 << 2, 0x6e, 0x65, 0x74, 0x74, 0x79, }); ByteBuf out = Unpooled.buffer(10); snappy.decode(in, out); }