Skip to content

Commit

Permalink
Issue #9554 - changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed May 1, 2023
1 parent d0294fc commit c2d2c1e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ public static char sanitizeFieldVchar(char c)
return c;
}


/**
* Checks whether this is an invalid VCHAR based on RFC9110.
* If this not a valid ISO-8859-1 character or a control character
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public MetaData decode(ByteBuffer buffer) throws HpackException.SessionException
if (LOG.isDebugEnabled())
LOG.debug(String.format("CtxTbl[%x] decoding %d octets", _context.hashCode(), buffer.remaining()));

// If the buffer is big, don't even think about decoding it
// If the buffer is big, don't even think about decoding it.
// Huffman may double the size, but it will only be a temporary allocation until detected in MetaDataBuilder.emit().
if (buffer.remaining() > _builder.getMaxSize())
throw new HpackException.SessionException("431 Request Header Fields too large");

Expand Down Expand Up @@ -169,7 +170,6 @@ public MetaData decode(ByteBuffer buffer) throws HpackException.SessionException
{
huffmanName = (buffer.get() & 0x80) == 0x80;
int length = integerDecode(buffer, 7);
_builder.checkSize(length, huffmanName);
if (huffmanName)
name = huffmanDecode(buffer, length);
else
Expand Down Expand Up @@ -210,7 +210,6 @@ public MetaData decode(ByteBuffer buffer) throws HpackException.SessionException
// decode the value
boolean huffmanValue = (buffer.get() & 0x80) == 0x80;
int length = integerDecode(buffer, 7);
_builder.checkSize(length, huffmanValue);
if (huffmanValue)
value = huffmanDecode(buffer, length);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,4 @@ public MetaData build() throws HpackException.StreamException
_contentLength = -1;
}
}

/**
* Check that the max size will not be exceeded.
*
* @param length the length
* @param huffman the huffman name
* @throws SessionException in case of size errors
*/
public void checkSize(int length, boolean huffman) throws SessionException
{
if (length < 0)
throw new IllegalArgumentException();

// Apply a huffman fudge factor
if (huffman)
length = Math.multiplyExact(length, 4) / 3;
if (Math.addExact(_size, length) > _maxSize)
throw new SessionException("Header too large %d > %d", _size + length, _maxSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public boolean decode(long streamId, ByteBuffer buffer, Handler handler) throws
LOG.debug("Decoding: streamId={}, buffer={}", streamId, BufferUtil.toDetailString(buffer));

// If the buffer is big, don't even think about decoding it
// Huffman may double the size, but it will only be a temporary allocation until detected in MetaDataBuilder.emit().
int maxHeaderSize = getMaxHeaderSize();
if (buffer.remaining() > maxHeaderSize)
throw new QpackException.SessionException(QPACK_DECOMPRESSION_FAILED, "header_too_large");
Expand Down

0 comments on commit c2d2c1e

Please sign in to comment.