diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index cb21b855..65553264 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -1240,7 +1240,12 @@ static int inflater_post_process_hd_entry(nghttp2_hd_context *inflater, static ssize_t inflate_decode(uint8_t **dest_ptr, uint8_t *in, size_t inlen, nghttp2_hd_side side) { - ssize_t declen = nghttp2_hd_huff_decode_count(in, inlen, side); + ssize_t declen; + if(inlen == 0) { + *dest_ptr = NULL; + return 0; + } + declen = nghttp2_hd_huff_decode_count(in, inlen, side); if(declen == -1) { return NGHTTP2_ERR_HEADER_COMP; } diff --git a/tests/main.c b/tests/main.c index 743956e9..5f1242aa 100644 --- a/tests/main.c +++ b/tests/main.c @@ -240,6 +240,8 @@ int main(int argc, char* argv[]) test_nghttp2_hd_inflate_newname_inc) || !CU_add_test(pSuite, "hd_inflate_clearall_inc", test_nghttp2_hd_inflate_clearall_inc) || + !CU_add_test(pSuite, "hd_inflate_zero_length_huffman", + test_nghttp2_hd_inflate_zero_length_huffman) || !CU_add_test(pSuite, "hd_change_table_size", test_nghttp2_hd_change_table_size) || !CU_add_test(pSuite, "hd_deflate_inflate", diff --git a/tests/nghttp2_hd_test.c b/tests/nghttp2_hd_test.c index 44e6ffe7..1365823e 100644 --- a/tests/nghttp2_hd_test.c +++ b/tests/nghttp2_hd_test.c @@ -689,6 +689,31 @@ void test_nghttp2_hd_inflate_clearall_inc(void) nghttp2_hd_inflate_free(&inflater); } +void test_nghttp2_hd_inflate_zero_length_huffman(void) +{ + nghttp2_hd_context inflater; + uint8_t buf[4]; + nghttp2_nv *resnva; + + /* Literal header without indexing - new name */ + buf[0] = 0x40; + buf[1] = 1; + buf[2] = 'x'; + buf[3] = 0x80; + + nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST); + CU_ASSERT(1 == nghttp2_hd_inflate_hd(&inflater, &resnva, buf, 4)); + + CU_ASSERT(1 == resnva[0].namelen); + CU_ASSERT('x' == resnva[0].name[0]); + CU_ASSERT(NULL == resnva[0].value); + CU_ASSERT(0 == resnva[0].valuelen); + + nghttp2_nv_array_del(resnva); + nghttp2_hd_end_headers(&inflater); + nghttp2_hd_inflate_free(&inflater); +} + void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_context deflater; diff --git a/tests/nghttp2_hd_test.h b/tests/nghttp2_hd_test.h index 9666132e..613ab322 100644 --- a/tests/nghttp2_hd_test.h +++ b/tests/nghttp2_hd_test.h @@ -36,6 +36,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void); void test_nghttp2_hd_inflate_newname_noinc(void); void test_nghttp2_hd_inflate_newname_inc(void); void test_nghttp2_hd_inflate_clearall_inc(void); +void test_nghttp2_hd_inflate_zero_length_huffman(void); void test_nghttp2_hd_change_table_size(void); void test_nghttp2_hd_deflate_inflate(void);