Skip to content
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

Better qpack fuzz #1775

Merged
merged 2 commits into from
Nov 15, 2024
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
13 changes: 9 additions & 4 deletions picohttp/h3zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,19 @@ uint8_t* h3zero_parse_qpack_header_value_string(uint8_t * bytes, uint8_t* decode
uint8_t * h3zero_parse_qpack_header_value(uint8_t * bytes, uint8_t * bytes_max,
http_header_enum_t header, h3zero_header_parts_t * parts)
{
uint64_t v_length;
int is_huffman;
uint64_t v_length = 0;
int is_huffman = 0;
uint8_t * decoded = NULL;
size_t decoded_length;
uint8_t deHuff[256];

is_huffman = (bytes[0] >> 7) & 1;
bytes = h3zero_qpack_int_decode(bytes, bytes_max, 0x7F, &v_length);
if (bytes >= bytes_max || bytes == NULL) {
bytes = NULL;
}
else {
is_huffman = (bytes[0] >> 7) & 1;
bytes = h3zero_qpack_int_decode(bytes, bytes_max, 0x7F, &v_length);
}
if (bytes != NULL) {
if (bytes + v_length > bytes_max) {
bytes = NULL;
Expand Down
18 changes: 18 additions & 0 deletions picoquictest/h3zerotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,11 +1157,29 @@ int h3zero_qpack_fuzz_test()
{
uint8_t* bytes = malloc(PICOQUIC_MAX_PACKET_SIZE);
size_t length = 0;
size_t test_length[4] = {1, 2, 3, 10000};
uint64_t random_context = 0x123456789ABCDEF0;
int ret = (bytes == NULL) ? -1 : 0;
int n_good = 0;
int n_trials = 0;

for (size_t x = 0; ret == 0 && x < nb_qpack_test_case; x++) {
for (length = 0; length < qpack_test_case[x].bytes_length - 1; length++) {
h3zero_header_parts_t parts = { 0 };
uint8_t* parsed = NULL;

memcpy(bytes, qpack_test_case[x].bytes, length);
if (length < sizeof(bytes)) {
memset(bytes + length, 0, sizeof(bytes) - length);
}

parsed = h3zero_parse_qpack_header_frame(bytes, bytes + length, &parts);
h3zero_release_header_parts(&parts);
n_good += (parsed != NULL) ? 1 : 0;
n_trials++;
}
}

for (int i = 0; ret == 0 && i < 512; i++) {
size_t x = (size_t)picoquic_test_uniform_random(&random_context, nb_qpack_test_case);

Expand Down
Loading