Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proxy/http2/HPACK.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ decode_string(Arena &arena, char **str, uint32_t &str_length, const uint8_t *buf
*str = arena.str_alloc(encoded_string_len * 2);

len = huffman_decode(*str, p, encoded_string_len);
if (len == HPACK_ERROR_COMPRESSION_ERROR) {
if (len < 0) {
return HPACK_ERROR_COMPRESSION_ERROR;
}
str_length = len;
Expand Down
25 changes: 20 additions & 5 deletions proxy/http2/HuffmanCodec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,44 @@ hpack_huffman_fin()
int64_t
huffman_decode(char *dst_start, const uint8_t *src, uint32_t src_len)
{
char *dst_end = dst_start;
uint8_t shift = 7;
Node *current = HUFFMAN_TREE_ROOT;
char *dst_end = dst_start;
uint8_t shift = 7;
Node *current = HUFFMAN_TREE_ROOT;
int byte_boundary_crossed = 0;
bool includes_zero = false;

while (src_len) {
if (*src & (1 << shift)) {
current = current->right;
} else {
current = current->left;
current = current->left;
includes_zero = true;
}

if (current->leaf_node == true) {
*dst_end = current->ascii_code;
++dst_end;
current = HUFFMAN_TREE_ROOT;
current = HUFFMAN_TREE_ROOT;
byte_boundary_crossed = 0;
includes_zero = false;
}
if (shift) {
--shift;
} else {
shift = 7;
++src;
--src_len;
++byte_boundary_crossed;
}
if (byte_boundary_crossed > 3) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking length of encoded data, right? It looks like some Huffman code has 3 byte boundaries. Is this should be 4? ( e.g. |11111111|11111111|11111110|0010 fffffe2 [28])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I thought >= 3 :p

return -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use HPACK_ERROR_COMPRESSION_ERROR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's in HPACK.h, so we shouldn't use it here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, here is HuffmanCodec. Got it.

}
}
if (byte_boundary_crossed > 1) {
return -1;
}
if (includes_zero) {
return -1;
}

return dst_end - dst_start;
Expand Down