Coverage Report

Created: 2026-06-15 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/nghttp2/lib/nghttp2_hd_huffman.h
Line
Count
Source
1
/*
2
 * nghttp2 - HTTP/2 C Library
3
 *
4
 * Copyright (c) 2013 Tatsuhiro Tsujikawa
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining
7
 * a copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sublicense, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be
15
 * included in all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 */
25
#ifndef NGHTTP2_HD_HUFFMAN_H
26
#define NGHTTP2_HD_HUFFMAN_H
27
28
#ifdef HAVE_CONFIG_H
29
#  include <config.h>
30
#endif /* defined(HAVE_CONFIG_H) */
31
32
#include <nghttp2/nghttp2.h>
33
34
/* FSA accepts this state as the end of huffman encoding sequence. */
35
82.3k
#define NGHTTP2_HUFF_ACCEPTED 0x01U
36
/* This state emits symbol */
37
3.06M
#define NGHTTP2_HUFF_SYM 0x02U
38
39
typedef struct {
40
  /* fstate is the current huffman decoding state, which is actually
41
     the node ID of internal huffman tree.  We have 257 leaf nodes,
42
     but they are identical to root node other than emitting a symbol,
43
     so we have 256 internal nodes [1..255], inclusive.  The node ID
44
     256 is a special node and it is a terminal state that means
45
     decoding failed. */
46
  uint16_t fstate;
47
  /* flags is the bitwise OR of zero or more of NGHTTP2_HUFF_*
48
     values. */
49
  uint8_t flags;
50
  /* symbol if NGHTTP2_HUFF_SYM flag set */
51
  uint8_t sym;
52
} nghttp2_huff_decode;
53
54
typedef nghttp2_huff_decode huff_decode_table_type[16];
55
56
typedef struct {
57
  /* fstate is the current huffman decoding state. */
58
  uint16_t fstate;
59
  uint8_t flags;
60
} nghttp2_hd_huff_decode_context;
61
62
typedef struct {
63
  /* The number of bits in this code */
64
  uint32_t nbits;
65
  /* Huffman code aligned to LSB */
66
  uint32_t code;
67
} nghttp2_huff_sym;
68
69
extern const nghttp2_huff_sym huff_sym_table[];
70
extern const nghttp2_huff_decode huff_decode_table[][16];
71
72
/*
73
 * nghttp2_huff_estimate_decode_length returns the estimated decoded
74
 * length of the huffman encoded string of length |len|.
75
 */
76
41.3k
static inline size_t nghttp2_huff_estimate_decode_length(size_t len) {
77
41.3k
  return len * 8 / 5;
78
41.3k
}
Unexecuted instantiation: fuzz_frames.cc:nghttp2_huff_estimate_decode_length(unsigned long)
Unexecuted instantiation: nghttp2_test_helper.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_frame.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_session.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_submit.c:nghttp2_huff_estimate_decode_length
nghttp2_hd.c:nghttp2_huff_estimate_decode_length
Line
Count
Source
76
41.3k
static inline size_t nghttp2_huff_estimate_decode_length(size_t len) {
77
41.3k
  return len * 8 / 5;
78
41.3k
}
Unexecuted instantiation: nghttp2_hd_huffman.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_hd_huffman_data.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_http.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_extpri.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_stream.c:nghttp2_huff_estimate_decode_length
Unexecuted instantiation: nghttp2_outbound_item.c:nghttp2_huff_estimate_decode_length
79
80
#endif /* !defined(NGHTTP2_HD_HUFFMAN_H) */