Issue #9554 - changes from review

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2023-05-01 19:23:02 +10:00
parent d0294fc10c
commit c2d2c1eadb
4 changed files with 3 additions and 23 deletions

View File

@ -264,7 +264,6 @@ public class HttpTokens
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

View File

@ -72,7 +72,8 @@ public class HpackDecoder
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");
@ -169,7 +170,6 @@ public class HpackDecoder
{
huffmanName = (buffer.get() & 0x80) == 0x80;
int length = integerDecode(buffer, 7);
_builder.checkSize(length, huffmanName);
if (huffmanName)
name = huffmanDecode(buffer, length);
else
@ -210,7 +210,6 @@ public class HpackDecoder
// 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

View File

@ -280,23 +280,4 @@ public class MetaDataBuilder
_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);
}
}

View File

@ -136,6 +136,7 @@ public class QpackDecoder implements Dumpable
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");