Skip to content

Commit 759e9ad

Browse files
Chenjpmarkt-asf
authored andcommitted
BZ 69762 - enhance
consider the possibility of integer overflow before result add.
1 parent 89770f2 commit 759e9ad

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

java/org/apache/coyote/http2/Hpack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int decodeInteger(ByteBuffer source, int n) throws HpackException {
179179
return -1;
180180
}
181181
b = source.get();
182-
result = result + (b & 127) * (PREFIX_TABLE[m] + 1);
182+
result = result + (b & 127) * (PREFIX_TABLE[m] + 1L);
183183
if (result > Integer.MAX_VALUE) {
184184
throw new HpackException(sm.getString("hpack.integerEncodedTooBig"));
185185
}

test/org/apache/coyote/http2/TestHpack.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ public void testDecodeIntegerMaxValuePlus1() throws HpackException {
178178
Hpack.decodeInteger(bb, 1);
179179
}
180180

181+
@Test(expected = HpackException.class)
182+
public void testDecodeIntegerOverflow() throws HpackException {
183+
ByteBuffer bb = ByteBuffer.allocate(9);
184+
bb.put((byte) 255);
185+
bb.put((byte) 254);
186+
bb.put((byte) 255);
187+
bb.put((byte) 255);
188+
bb.put((byte) 255);
189+
bb.put((byte) 15);
190+
bb.position(0);
191+
192+
Hpack.decodeInteger(bb, 1);
193+
}
181194

182195
@Test(expected = HpackException.class)
183196
public void testDecodeIntegerZeroValues() throws HpackException {

0 commit comments

Comments
 (0)