// Tail needs 1 last lookup in case the leftover is big enough for a match.
// Make sure match length <= available length
uint8_t leftover_len = 8 - cur_bit;
- uint8_t old_result = result.len;
+ uint8_t old_result_len = result.len;
+ HuffmanState old_result_state = result.state;
+
if (another_search && (leftover_len >= min_decode_len[state]))
{
result = huffman_decode[state][byte];
byte = (byte << result.len) | (((uint16_t)1 << result.len) - 1);
}
else
- result.len = old_result;
+ {
+ // Use leftover bits for padding check if previous lookup was a match
+ if (old_result_state == HUFFMAN_MATCH)
+ result.len = leftover_len;
+ else
+ result.len = old_result_len;
+ }
}
// Padding check
CHECK(memcmp(res, expected, 16) == 0);
}
+TEST(http2_hpack_string_decode_success, huffman_decoding_tail_lookup_unsucessful)
+{
+ // tail lookup unsuccessful after successful previous match
+ // decodes to 9D
+ uint8_t buf[3] = {0x82, 0x7E, 0xFF};
+ // decode
+ uint32_t bytes_processed = 0, bytes_written = 0;
+ uint8_t res[3];
+ bool success = decode->translate(buf, 3, bytes_processed, res, 3, bytes_written, &events, &inf);
+ // check results
+ CHECK(success == true);
+ CHECK(bytes_processed == 3);
+ CHECK(bytes_written == 2);
+}
+
//
// The following tests should trigger infractions/events
//