-
Notifications
You must be signed in to change notification settings - Fork 857
Check HPACK Huffman code strictly #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
| return -1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
There was a problem hiding this comment.
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])There was a problem hiding this comment.
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