Skip to content

Commit

Permalink
UNDERTOW-1150 Hpack ArrayOutOfBound exception when client sends inval…
Browse files Browse the repository at this point in the history
…id index
  • Loading branch information
stuartwdouglas committed Aug 10, 2017
1 parent dc74ba5 commit 5e8670a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/io/undertow/UndertowMessages.java
Expand Up @@ -544,4 +544,6 @@ public interface UndertowMessages {
@Message(id = 174, value = "An invalid escape character in cookie value")
IllegalArgumentException invalidEscapeCharacter();

@Message(id = 175, value = "Invalid Hpack index %s")
HpackException invalidHpackIndex(int index);
}
Expand Up @@ -304,11 +304,15 @@ private void handleIndex(int index) throws HpackException {
* @param index The index from the hpack
* @return the real index into the array
*/
int getRealIndex(int index) {
int getRealIndex(int index) throws HpackException {
//the index is one based, but our table is zero based, hence -1
//also because of our ring buffer setup the indexes are reversed
//index = 1 is at position firstSlotPosition + filledSlots
return (firstSlotPosition + (filledTableSlots - index)) % headerTable.length;
int newIndex = (firstSlotPosition + (filledTableSlots - index)) % headerTable.length;
if(newIndex < 0) {
throw UndertowMessages.MESSAGES.invalidHpackIndex(index);
}
return newIndex;
}

private void addStaticTableEntry(int index) throws HpackException {
Expand Down
Expand Up @@ -389,7 +389,7 @@ public void testExample_D_2_112() throws HpackException {
}


private static void assertTableState(HpackDecoder decoder, int index, String name, String value) {
private static void assertTableState(HpackDecoder decoder, int index, String name, String value) throws HpackException {
int idx = decoder.getRealIndex(index);
Hpack.HeaderField val = decoder.getHeaderTable()[idx];
Assert.assertEquals(name, val.name.toString());
Expand Down

0 comments on commit 5e8670a

Please sign in to comment.