HpackDecoder { static int decodeULE128(ByteBuf in, int result) throws Http2Exception { final int readerIndex = in.readerIndex(); final long v = decodeULE128(in, (long) result); if (v > Integer.MAX_VALUE) { in.readerIndex(readerIndex); throw DECODE_ULE_128_TO_INT_DECOMPRESSION_EXCEPTION; } return (int) v; } HpackDecoder(long maxHeaderListSize, int initialHuffmanDecodeCapacity);   HpackDecoder(long maxHeaderListSize, int initialHuffmanDecodeCapacity, int maxHeaderTableSize); void decode(int streamId, ByteBuf in, Http2Headers headers); void setMaxHeaderTableSize(long maxHeaderTableSize); void setMaxHeaderListSize(long maxHeaderListSize, long maxHeaderListSizeGoAway); long getMaxHeaderListSize(); long getMaxHeaderListSizeGoAway(); long getMaxHeaderTableSize();  }
@Test public void testDecodeULE128IntMax() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x07}; ByteBuf in = Unpooled.wrappedBuffer(input); try { assertEquals(MAX_VALUE, decodeULE128(in, 0)); } finally { in.release(); } }
@Test(expected = Http2Exception.class) public void testDecodeULE128IntOverflow1() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x07}; ByteBuf in = Unpooled.wrappedBuffer(input); final int readerIndex = in.readerIndex(); try { decodeULE128(in, 1); } finally { assertEquals(readerIndex, in.readerIndex()); in.release(); } }
@Test(expected = Http2Exception.class) public void testDecodeULE128IntOverflow2() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x08}; ByteBuf in = Unpooled.wrappedBuffer(input); final int readerIndex = in.readerIndex(); try { decodeULE128(in, 0); } finally { assertEquals(readerIndex, in.readerIndex()); in.release(); } }
@Test public void testDecodeULE128LongMax() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F}; ByteBuf in = Unpooled.wrappedBuffer(input); try { assertEquals(Long.MAX_VALUE, decodeULE128(in, 0L)); } finally { in.release(); } }
@Test(expected = Http2Exception.class) public void testDecodeULE128LongOverflow1() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; ByteBuf in = Unpooled.wrappedBuffer(input); final int readerIndex = in.readerIndex(); try { decodeULE128(in, 0L); } finally { assertEquals(readerIndex, in.readerIndex()); in.release(); } }
@Test(expected = Http2Exception.class) public void testDecodeULE128LongOverflow2() throws Http2Exception { byte[] input = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F}; ByteBuf in = Unpooled.wrappedBuffer(input); final int readerIndex = in.readerIndex(); try { decodeULE128(in, 1L); } finally { assertEquals(readerIndex, in.readerIndex()); in.release(); } }