hpack_parser.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <assert.h>
24 #include <inttypes.h>
25 #include <stddef.h>
26 #include <stdlib.h>
27 
28 #include <algorithm>
29 #include <cstdint>
30 #include <string>
31 #include <utility>
32 
33 #include "absl/base/attributes.h"
34 #include "absl/status/status.h"
35 #include "absl/strings/match.h"
36 #include "absl/strings/str_cat.h"
37 #include "absl/strings/str_format.h"
38 #include "absl/strings/string_view.h"
39 #include "absl/types/optional.h"
40 #include "absl/types/span.h"
41 #include "absl/types/variant.h"
42 
43 #include <grpc/status.h>
44 #include <grpc/support/log.h>
45 
59 
60 // IWYU pragma: no_include <type_traits>
61 
62 #if __cplusplus > 201103L
63 #define GRPC_HPACK_CONSTEXPR_FN constexpr
64 #define GRPC_HPACK_CONSTEXPR_VALUE constexpr
65 #else
66 #define GRPC_HPACK_CONSTEXPR_FN
67 #define GRPC_HPACK_CONSTEXPR_VALUE const
68 #endif
69 
70 namespace grpc_core {
71 
72 TraceFlag grpc_trace_chttp2_hpack_parser(false, "chttp2_hpack_parser");
73 
74 /* state table for huffman decoding: given a state, gives an index/16 into
75  next_sub_tbl. Taking that index and adding the value of the nibble being
76  considered returns the next state.
77 
78  generated by gen_hpack_tables.c */
79 static const uint8_t next_tbl[256] = {
80  0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1,
81  1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
82  14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1,
83  1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1,
84  1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2,
85  26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1,
86  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2,
87  2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1,
88  1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9,
89  38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
90  1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
91  41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
92  3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
93 };
94 
95 /* next state, based upon current state and the current nibble: see above.
96  generated by gen_hpack_tables.c */
97 static const int16_t next_sub_tbl[48 * 16] = {
98  1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
99  218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15,
100  16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3,
101  7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8,
102  4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
103  199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0,
104  0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140,
105  141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24,
106  4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0,
107  0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8,
108  4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110  0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4,
111  8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26,
112  27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3,
113  7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43,
114  2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11,
115  24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
116  44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50,
117  51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119  0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
120  68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121  0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82,
122  83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11,
123  24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7,
124  11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94,
125  95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24,
126  4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4,
127  8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128  0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4,
129  8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
130  0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
131  131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8,
132  4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148,
133  149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0,
134  0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11,
135  24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7,
136  11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
137  157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172,
138  173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
139  188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8,
140  4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4,
141  8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24,
142  4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11,
143  24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8,
144  4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229,
145  230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
146  4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
147  0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
148  253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149  0, 0, 255,
150 };
151 
152 /* emission table: indexed like next_tbl, ultimately gives the byte to be
153  emitted, or -1 for no byte, or 256 for end of stream
154 
155  generated by gen_hpack_tables.c */
156 static const uint16_t emit_tbl[256] = {
157  0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13,
158  14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27,
159  28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
160  43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56,
161  57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0,
162  71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
163  86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
164  101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
165  116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
166  131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
167  146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0,
168  160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
169  0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
170  189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
171  204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
172  219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
173  233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
174  248,
175 };
176 
177 /* generated by gen_hpack_tables.c */
178 static const int16_t emit_sub_tbl[249 * 16] = {
179  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
180  -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49,
181  49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97,
182  97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101,
183  105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1,
184  -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37,
185  37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105,
186  105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46,
187  47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61,
188  61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116,
189  116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100,
190  102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58,
191  58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51,
192  51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61,
193  65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108,
194  108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68,
195  69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
196  84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1,
197  -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42,
198  42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59,
199  59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90,
200  90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63,
201  39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62,
202  62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36,
203  64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69,
204  69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71,
205  71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
206  73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75,
207  75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77,
208  77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79,
209  79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81,
210  81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82,
211  83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84,
212  84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86,
213  86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89,
214  89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107,
215  107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118,
216  118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120,
217  120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122,
218  122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42,
219  44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90,
220  90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39,
221  39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124,
222  124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36,
223  64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60,
224  60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123,
225  123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92,
226  92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195,
227  208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130,
228  130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194,
229  194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167,
230  167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217,
231  227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160,
232  163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228,
233  232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135,
234  135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137,
235  138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139,
236  139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141,
237  141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147,
238  147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150,
239  150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152,
240  152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157,
241  157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165,
242  165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166,
243  168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174,
244  174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180,
245  180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183,
246  183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191,
247  191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231,
248  231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9,
249  9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148,
250  148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206,
251  215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237,
252  237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205,
253  210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203,
254  203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211,
255  211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214,
256  214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222,
257  222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241,
258  241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244,
259  245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246,
260  246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248,
261  248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251,
262  251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253,
263  253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2,
264  2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6,
265  6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12,
266  12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
267  17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20,
268  20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25,
269  25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29,
270  29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127,
271  220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93,
272  93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195,
273  208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128,
274  128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130,
275  131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162,
276  162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194,
277  194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226,
278  226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167,
279  172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179,
280  179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227,
281  227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133,
282  133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163,
283  164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186,
284  186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232,
285  233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152,
286  155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231,
287  239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9,
288  9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144,
289  144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148,
290  148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159,
291  171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206,
292  206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225,
293  225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237,
294  237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234,
295  235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205,
296  205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242,
297  243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245,
298  246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1,
299  -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2,
300  2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
301  4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
302  6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
303  8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
304  12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
305  15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17,
306  17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
307  19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
308  20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23,
309  23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
310  25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27,
311  27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29,
312  29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31,
313  31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220,
314  220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249,
315  10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67,
316  67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95,
317  95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100,
318  100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103,
319  103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108,
320  108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110,
321  110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114,
322  114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117,
323  58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68,
324  68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72,
325  72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76,
326  76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79,
327  80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83,
328  83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87,
329  87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113,
330  113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120,
331  121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59,
332  59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33,
333  33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40,
334  40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63,
335  63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124,
336  124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94,
337  94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60,
338  60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1,
339  92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130,
340  130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161,
341  167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1,
342  -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132,
343  132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134,
344  134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146,
345  146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156,
346  156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160,
347  163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164,
348  164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170,
349  170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178,
350  178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185,
351  185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187,
352  187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190,
353  190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198,
354  198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228,
355  232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233,
356  233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138,
357  138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143,
358  143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150,
359  151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157,
360  157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168,
361  168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182,
362  182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191,
363  197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142,
364  142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215,
365  225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192,
366  192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200,
367  200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202,
368  202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210,
369  210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218,
370  218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219,
371  238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240,
372  240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243,
373  243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204,
374  204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214,
375  221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241,
376  241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247,
377  247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252,
378  252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3,
379  4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14,
380  14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21,
381  23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
382  30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10,
383  10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22,
384  22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45,
385  45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47,
386  47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51,
387  52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53,
388  53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55,
389  55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57,
390  57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97,
391  97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101,
392  101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111,
393  111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116,
394  116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37,
395  45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51,
396  51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55,
397  55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65,
398  65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100,
399  102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108,
400  108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114,
401  114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69,
402  69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76,
403  77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84,
404  84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113,
405  118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88,
406  90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40,
407  41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35,
408  62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36,
409  36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91,
410  91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93,
411  126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125,
412  125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208,
413  128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153,
414  153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167,
415  167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176,
416  176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179,
417  179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216,
418  216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217,
419  227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229,
420  229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132,
421  132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146,
422  146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160,
423  163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170,
424  170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185,
425  185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190,
426  190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228,
427  232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138,
428  138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150,
429  151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168,
430  168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191,
431  197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215,
432  225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199,
433  199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234,
434  234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235,
435  192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201,
436  201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213,
437  213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240,
438  240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255,
439  203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223,
440  223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250,
441  251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
442  11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
443  28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
444  13, 22, 22, 22, 22, 256, 256, 256, 256,
445 };
446 
447 namespace {
448 // The alphabet used for base64 encoding binary metadata.
449 constexpr char kBase64Alphabet[] =
450  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
451 
452 // An inverted table: for each value in kBase64Alphabet, table contains the
453 // index with which it's stored, so we can quickly invert the encoding without
454 // any complicated runtime logic.
455 struct Base64InverseTable {
456  uint8_t table[256]{};
457  GRPC_HPACK_CONSTEXPR_FN Base64InverseTable() {
458  for (int i = 0; i < 256; i++) {
459  table[i] = 255;
460  }
461  for (const char* p = kBase64Alphabet; *p; p++) {
462  uint8_t idx = *p;
463  uint8_t ofs = p - kBase64Alphabet;
464  table[idx] = ofs;
465  }
466  }
467 };
468 
469 GRPC_HPACK_CONSTEXPR_VALUE Base64InverseTable kBase64InverseTable;
470 } // namespace
471 
472 // Input tracks the current byte through the input data and provides it
473 // via a simple stream interface.
475  public:
476  Input(grpc_slice_refcount* current_slice_refcount, const uint8_t* begin,
477  const uint8_t* end)
478  : current_slice_refcount_(current_slice_refcount),
479  begin_(begin),
480  end_(end),
481  frontier_(begin) {}
482 
483  // If input is backed by a slice, retrieve its refcount. If not, return
484  // nullptr.
486 
487  // Have we reached the end of input?
488  bool end_of_stream() const { return begin_ == end_; }
489  // How many bytes until end of input
490  size_t remaining() const { return end_ - begin_; }
491  // Current position, as a pointer
492  const uint8_t* cur_ptr() const { return begin_; }
493  // End position, as a pointer
494  const uint8_t* end_ptr() const { return end_; }
495  // Move read position forward by n, unchecked
496  void Advance(size_t n) { begin_ += n; }
497 
498  // Retrieve the current character, or nullopt if end of stream
499  // Do not advance
501  if (end_of_stream()) {
502  return {};
503  }
504  return *begin_;
505  }
506 
507  // Retrieve and advance past the current character, or return nullopt if end
508  // of stream
510  if (end_of_stream()) {
512  }
513  return *begin_++;
514  }
515 
516  // Helper to parse a varint delta on top of value, return nullopt on failure
517  // (setting error)
519  // TODO(ctiller): break out a variant of this when we know there are at
520  // least 5 bytes in input_
521  auto cur = Next();
522  if (!cur) return {};
523  value += *cur & 0x7f;
524  if ((*cur & 0x80) == 0) return value;
525 
526  cur = Next();
527  if (!cur) return {};
528  value += (*cur & 0x7f) << 7;
529  if ((*cur & 0x80) == 0) return value;
530 
531  cur = Next();
532  if (!cur) return {};
533  value += (*cur & 0x7f) << 14;
534  if ((*cur & 0x80) == 0) return value;
535 
536  cur = Next();
537  if (!cur) return {};
538  value += (*cur & 0x7f) << 21;
539  if ((*cur & 0x80) == 0) return value;
540 
541  cur = Next();
542  if (!cur) return {};
543  uint32_t c = (*cur) & 0x7f;
544  // We might overflow here, so we need to be a little careful about the
545  // addition
546  if (c > 0xf) return ParseVarintOutOfRange(value, *cur);
547  const uint32_t add = c << 28;
548  if (add > 0xffffffffu - value) {
549  return ParseVarintOutOfRange(value, *cur);
550  }
551  value += add;
552  if ((*cur & 0x80) == 0) return value;
553 
554  // Spec weirdness: we can add an infinite stream of 0x80 at the end of a
555  // varint and still end up with a correctly encoded varint.
556  do {
557  cur = Next();
558  if (!cur.has_value()) return {};
559  } while (*cur == 0x80);
560 
561  // BUT... the last byte needs to be 0x00 or we'll overflow dramatically!
562  if (*cur == 0) return value;
563  return ParseVarintOutOfRange(value, *cur);
564  }
565 
566  // Prefix for a string
567  struct StringPrefix {
568  // Number of bytes in input for string
570  // Is it huffman compressed
571  bool huff;
572  };
573 
574  // Parse a string prefix
576  auto cur = Next();
577  if (!cur.has_value()) return {};
578  // Huffman if the top bit is 1
579  const bool huff = (*cur & 0x80) != 0;
580  // String length
581  uint32_t strlen = (*cur & 0x7f);
582  if (strlen == 0x7f) {
583  // all ones ==> varint string length
584  auto v = ParseVarint(0x7f);
585  if (!v.has_value()) return {};
586  strlen = *v;
587  }
588  return StringPrefix{strlen, huff};
589  }
590 
591  // Check if we saw an EOF.. must be verified before looking at TakeError
592  bool eof_error() const { return eof_error_; }
593 
594  // Extract the parse error, leaving the current error as NONE.
598  return out;
599  }
600 
601  // Set the current error - allows the rest of the code not to need to pass
602  // around StatusOr<> which would be prohibitive here.
606  return;
607  }
608  error_ = error;
609  begin_ = end_;
610  }
611 
612  // If no error is set, set it to the value produced by error_factory.
613  // Return return_value unchanged.
614  template <typename F, typename T>
616  T return_value) {
617  if (!GRPC_ERROR_IS_NONE(error_) || eof_error_) return return_value;
618  error_ = error_factory();
619  begin_ = end_;
620  return return_value;
621  }
622 
623  // Set the error to an unexpected eof, and return result (code golfed as this
624  // is a common case)
625  template <typename T>
626  T UnexpectedEOF(T return_value) {
627  if (!GRPC_ERROR_IS_NONE(error_)) return return_value;
628  eof_error_ = true;
629  return return_value;
630  }
631 
632  // Update the frontier - signifies we've successfully parsed another element
634 
635  // Get the frontier - for buffering should we fail due to eof
636  const uint8_t* frontier() const { return frontier_; }
637 
638  private:
639  // Helper to set the error to out of range for ParseVarint
641  uint8_t last_byte) {
642  return MaybeSetErrorAndReturn(
643  [value, last_byte] {
645  "integer overflow in hpack integer decoding: have 0x%08x, "
646  "got byte 0x%02x on byte 5",
647  value, last_byte));
648  },
650  }
651 
652  // Refcount if we are backed by a slice
654  // Current input point
655  const uint8_t* begin_;
656  // End of stream point
657  const uint8_t* const end_;
658  // Frontier denotes the first byte past successfully processed input
660  // Current error
662  // If the error was EOF, we flag it here..
663  bool eof_error_ = false;
664 };
665 
666 // Helper to parse a string and turn it into a slice with appropriate memory
667 // management characteristics
669  public:
670  String(const String&) = delete;
671  String& operator=(const String&) = delete;
672  String(String&& other) noexcept : value_(std::move(other.value_)) {
673  other.value_ = absl::Span<const uint8_t>();
674  }
675  String& operator=(String&& other) noexcept {
676  value_ = std::move(other.value_);
677  other.value_ = absl::Span<const uint8_t>();
678  return *this;
679  }
680 
681  // Take the value and leave this empty
682  Slice Take();
683 
684  // Return a reference to the value as a string view
686  if (auto* p = absl::get_if<Slice>(&value_)) {
687  return p->as_string_view();
688  } else if (auto* p = absl::get_if<absl::Span<const uint8_t>>(&value_)) {
689  return absl::string_view(reinterpret_cast<const char*>(p->data()),
690  p->size());
691  } else if (auto* p = absl::get_if<std::vector<uint8_t>>(&value_)) {
692  return absl::string_view(reinterpret_cast<const char*>(p->data()),
693  p->size());
694  }
696  }
697 
698  // Parse a non-binary string
700  auto pfx = input->ParseStringPrefix();
701  if (!pfx.has_value()) return {};
702  if (pfx->huff) {
703  // Huffman coded
704  std::vector<uint8_t> output;
705  auto v = ParseHuff(input, pfx->length,
706  [&output](uint8_t c) { output.push_back(c); });
707  if (!v) return {};
708  return String(std::move(output));
709  }
710  return ParseUncompressed(input, pfx->length);
711  }
712 
713  // Parse a binary string
715  auto pfx = input->ParseStringPrefix();
716  if (!pfx.has_value()) return {};
717  if (!pfx->huff) {
718  if (pfx->length > 0 && input->peek() == 0) {
719  // 'true-binary'
720  input->Advance(1);
721  return ParseUncompressed(input, pfx->length - 1);
722  }
723  // Base64 encoded... pull out the string, then unbase64 it
724  auto base64 = ParseUncompressed(input, pfx->length);
725  if (!base64.has_value()) return {};
726  return Unbase64(input, std::move(*base64));
727  } else {
728  // Huffman encoded...
729  std::vector<uint8_t> decompressed;
730  // State here says either we don't know if it's base64 or binary, or we do
731  // and what is it.
732  enum class State { kUnsure, kBinary, kBase64 };
733  State state = State::kUnsure;
734  auto decompressed_ok =
735  ParseHuff(input, pfx->length, [&state, &decompressed](uint8_t c) {
736  if (state == State::kUnsure) {
737  // First byte... if it's zero it's binary
738  if (c == 0) {
739  // Save the type, and skip the zero
740  state = State::kBinary;
741  return;
742  } else {
743  // Flag base64, store this value
744  state = State::kBase64;
745  }
746  }
747  // Non-first byte, or base64 first byte
748  decompressed.push_back(c);
749  });
750  if (!decompressed_ok) return {};
751  switch (state) {
752  case State::kUnsure:
753  // No bytes, empty span
755  case State::kBinary:
756  // Binary, we're done
757  return String(std::move(decompressed));
758  case State::kBase64:
759  // Base64 - unpack it
760  return Unbase64(input, String(std::move(decompressed)));
761  }
762  GPR_UNREACHABLE_CODE(abort(););
763  }
764  }
765 
766  private:
767  void AppendBytes(const uint8_t* data, size_t length);
768  explicit String(std::vector<uint8_t> v) : value_(std::move(v)) {}
771  : value_(Slice::FromRefcountAndBytes(r, begin, end)) {}
772 
773  // Parse some huffman encoded bytes, using output(uint8_t b) to emit each
774  // decoded byte.
775  template <typename Out>
776  static bool ParseHuff(Input* input, uint32_t length, Out output) {
778  int16_t state = 0;
779  // Parse one half byte... we leverage some lookup tables to keep the logic
780  // here really simple.
781  auto nibble = [&output, &state](uint8_t nibble) {
782  int16_t emit = emit_sub_tbl[16 * emit_tbl[state] + nibble];
783  int16_t next = next_sub_tbl[16 * next_tbl[state] + nibble];
784  if (emit != -1) {
785  if (emit >= 0 && emit < 256) {
786  output(static_cast<uint8_t>(emit));
787  } else {
788  assert(emit == 256);
789  }
790  }
791  state = next;
792  };
793  // If there's insufficient bytes remaining, return now.
794  if (input->remaining() < length) {
795  return input->UnexpectedEOF(false);
796  }
797  // Grab the byte range, and iterate through it.
798  const uint8_t* p = input->cur_ptr();
799  input->Advance(length);
800  for (uint32_t i = 0; i < length; i++) {
801  nibble(p[i] >> 4);
802  nibble(p[i] & 0xf);
803  }
804  return true;
805  }
806 
807  // Parse some uncompressed string bytes.
809  uint32_t length) {
811  // Check there's enough bytes
812  if (input->remaining() < length) {
813  return input->UnexpectedEOF(absl::optional<String>());
814  }
815  auto* refcount = input->slice_refcount();
816  auto* p = input->cur_ptr();
817  input->Advance(length);
818  if (refcount != nullptr) {
819  return String(refcount, p, p + length);
820  } else {
822  }
823  }
824 
825  // Turn base64 encoded bytes into not base64 encoded bytes.
826  // Only takes input to set an error on failure.
829  if (auto* p = absl::get_if<Slice>(&s.value_)) {
830  result = Unbase64Loop(p->begin(), p->end());
831  }
832  if (auto* p = absl::get_if<absl::Span<const uint8_t>>(&s.value_)) {
833  result = Unbase64Loop(p->begin(), p->end());
834  }
835  if (auto* p = absl::get_if<std::vector<uint8_t>>(&s.value_)) {
836  result = Unbase64Loop(p->data(), p->data() + p->size());
837  }
838  if (!result.has_value()) {
839  return input->MaybeSetErrorAndReturn(
840  [] {
842  "illegal base64 encoding");
843  },
845  }
846  return String(std::move(*result));
847  }
848 
849  // Main loop for Unbase64
851  const uint8_t* end) {
852  while (cur != end && end[-1] == '=') {
853  --end;
854  }
855 
856  std::vector<uint8_t> out;
857  out.reserve(3 * (end - cur) / 4 + 3);
858 
859  // Decode 4 bytes at a time while we can
860  while (end - cur >= 4) {
861  uint32_t bits = kBase64InverseTable.table[*cur];
862  if (bits > 63) return {};
863  uint32_t buffer = bits << 18;
864  ++cur;
865 
866  bits = kBase64InverseTable.table[*cur];
867  if (bits > 63) return {};
868  buffer |= bits << 12;
869  ++cur;
870 
871  bits = kBase64InverseTable.table[*cur];
872  if (bits > 63) return {};
873  buffer |= bits << 6;
874  ++cur;
875 
876  bits = kBase64InverseTable.table[*cur];
877  if (bits > 63) return {};
878  buffer |= bits;
879  ++cur;
880 
881  out.insert(out.end(), {static_cast<uint8_t>(buffer >> 16),
882  static_cast<uint8_t>(buffer >> 8),
883  static_cast<uint8_t>(buffer)});
884  }
885  // Deal with the last 0, 1, 2, or 3 bytes.
886  switch (end - cur) {
887  case 0:
888  return out;
889  case 1:
890  return {};
891  case 2: {
892  uint32_t bits = kBase64InverseTable.table[*cur];
893  if (bits > 63) return {};
894  uint32_t buffer = bits << 18;
895 
896  ++cur;
897  bits = kBase64InverseTable.table[*cur];
898  if (bits > 63) return {};
899  buffer |= bits << 12;
900 
901  if (buffer & 0xffff) return {};
902  out.push_back(static_cast<uint8_t>(buffer >> 16));
903  return out;
904  }
905  case 3: {
906  uint32_t bits = kBase64InverseTable.table[*cur];
907  if (bits > 63) return {};
908  uint32_t buffer = bits << 18;
909 
910  ++cur;
911  bits = kBase64InverseTable.table[*cur];
912  if (bits > 63) return {};
913  buffer |= bits << 12;
914 
915  ++cur;
916  bits = kBase64InverseTable.table[*cur];
917  if (bits > 63) return {};
918  buffer |= bits << 6;
919 
920  ++cur;
921  if (buffer & 0xff) return {};
922  out.push_back(static_cast<uint8_t>(buffer >> 16));
923  out.push_back(static_cast<uint8_t>(buffer >> 8));
924  return out;
925  }
926  }
927 
928  GPR_UNREACHABLE_CODE(return out;);
929  }
930 
932 };
933 
934 // Parser parses one key/value pair from a byte stream.
936  public:
937  Parser(Input* input, grpc_metadata_batch* metadata_buffer,
938  uint32_t metadata_size_limit, HPackTable* table,
939  uint8_t* dynamic_table_updates_allowed, uint32_t* frame_length,
940  LogInfo log_info)
941  : input_(input),
942  metadata_buffer_(metadata_buffer),
943  table_(table),
944  dynamic_table_updates_allowed_(dynamic_table_updates_allowed),
945  frame_length_(frame_length),
946  metadata_size_limit_(metadata_size_limit),
947  log_info_(log_info) {}
948 
949  // Skip any priority bits, or return false on failure
950  bool SkipPriority() {
951  if (input_->remaining() < 5) return input_->UnexpectedEOF(false);
952  input_->Advance(5);
953  return true;
954  }
955 
956  bool Parse() {
957  auto cur = *input_->Next();
958  switch (cur >> 4) {
959  // Literal header not indexed - First byte format: 0000xxxx
960  // Literal header never indexed - First byte format: 0001xxxx
961  // Where xxxx:
962  // 0000 - literal key
963  // 1111 - indexed key, varint encoded index
964  // other - indexed key, inline encoded index
965  case 0:
966  case 1:
967  switch (cur & 0xf) {
968  case 0: // literal key
969  return FinishHeaderOmitFromTable(ParseLiteralKey());
970  case 0xf: // varint encoded key index
971  return FinishHeaderOmitFromTable(ParseVarIdxKey(0xf));
972  default: // inline encoded key index
973  return FinishHeaderOmitFromTable(ParseIdxKey(cur & 0xf));
974  }
975  // Update max table size.
976  // First byte format: 001xxxxx
977  // Where xxxxx:
978  // 11111 - max size is varint encoded
979  // other - max size is stored inline
980  case 2:
981  // inline encoded max table size
982  return FinishMaxTableSize(cur & 0x1f);
983  case 3:
984  if (cur == 0x3f) {
985  // varint encoded max table size
986  return FinishMaxTableSize(input_->ParseVarint(0x1f));
987  } else {
988  // inline encoded max table size
989  return FinishMaxTableSize(cur & 0x1f);
990  }
991  // Literal header with incremental indexing.
992  // First byte format: 01xxxxxx
993  // Where xxxxxx:
994  // 000000 - literal key
995  // 111111 - indexed key, varint encoded index
996  // other - indexed key, inline encoded index
997  case 4:
998  if (cur == 0x40) {
999  // literal key
1000  return FinishHeaderAndAddToTable(ParseLiteralKey());
1001  }
1003  case 5:
1004  case 6:
1005  // inline encoded key index
1006  return FinishHeaderAndAddToTable(ParseIdxKey(cur & 0x3f));
1007  case 7:
1008  if (cur == 0x7f) {
1009  // varint encoded key index
1010  return FinishHeaderAndAddToTable(ParseVarIdxKey(0x3f));
1011  } else {
1012  // inline encoded key index
1013  return FinishHeaderAndAddToTable(ParseIdxKey(cur & 0x3f));
1014  }
1015  // Indexed Header Field Representation
1016  // First byte format: 1xxxxxxx
1017  // Where xxxxxxx:
1018  // 0000000 - illegal
1019  // 1111111 - varint encoded field index
1020  // other - inline encoded field index
1021  case 8:
1022  if (cur == 0x80) {
1023  // illegal value.
1024  return input_->MaybeSetErrorAndReturn(
1025  [] {
1027  "Illegal hpack op code");
1028  },
1029  false);
1030  }
1032  case 9:
1033  case 10:
1034  case 11:
1035  case 12:
1036  case 13:
1037  case 14:
1038  // inline encoded field index
1039  return FinishIndexed(cur & 0x7f);
1040  case 15:
1041  if (cur == 0xff) {
1042  // varint encoded field index
1043  return FinishIndexed(input_->ParseVarint(0x7f));
1044  } else {
1045  // inline encoded field index
1046  return FinishIndexed(cur & 0x7f);
1047  }
1048  }
1049  GPR_UNREACHABLE_CODE(abort());
1050  }
1051 
1052  private:
1054  const char* type;
1055  switch (log_info_.type) {
1056  case LogInfo::kHeaders:
1057  type = "HDR";
1058  break;
1059  case LogInfo::kTrailers:
1060  type = "TRL";
1061  break;
1062  case LogInfo::kDontKnow:
1063  type = "???";
1064  break;
1065  }
1066  gpr_log(GPR_DEBUG, "HTTP:%d:%s:%s: %s", log_info_.stream_id, type,
1067  log_info_.is_client ? "CLI" : "SVR", memento.DebugString().c_str());
1068  }
1069 
1071  // Pass up to the transport
1072  if (GPR_UNLIKELY(metadata_buffer_ == nullptr)) return true;
1073  *frame_length_ += md.transport_size();
1074  if (GPR_UNLIKELY(*frame_length_ > metadata_size_limit_)) {
1075  return HandleMetadataSizeLimitExceeded(md);
1076  }
1077 
1078  metadata_buffer_->Set(md);
1079  return true;
1080  }
1081 
1083  // Allow higher code to just pass in failures ... simplifies things a bit.
1084  if (!md.has_value()) return false;
1085  // Log if desired
1087  LogHeader(*md);
1088  }
1089  // Emit whilst we own the metadata.
1090  auto r = EmitHeader(*md);
1091  // Add to the hpack table
1094  input_->SetError(err);
1095  return false;
1096  };
1097  return r;
1098  }
1099 
1101  // Allow higher code to just pass in failures ... simplifies things a bit.
1102  if (!md.has_value()) return false;
1103  return FinishHeaderOmitFromTable(*md);
1104  }
1105 
1107  // Log if desired
1109  LogHeader(md);
1110  }
1111  return EmitHeader(md);
1112  }
1113 
1114  // Parse a string encoded key and a string encoded value
1116  auto key = String::Parse(input_);
1117  if (!key.has_value()) return {};
1118  auto value = ParseValueString(absl::EndsWith(key->string_view(), "-bin"));
1119  if (GPR_UNLIKELY(!value.has_value())) {
1120  return {};
1121  }
1122  auto key_string = key->string_view();
1123  auto value_slice = value->Take();
1124  const auto transport_size = key_string.size() + value_slice.size() +
1127  key->string_view(), std::move(value_slice), transport_size,
1128  [key_string](absl::string_view error, const Slice& value) {
1129  ReportMetadataParseError(key_string, error, value.as_string_view());
1130  });
1131  }
1132 
1133  // Parse an index encoded key and a string encoded value
1135  const auto* elem = table_->Lookup(index);
1136  if (GPR_UNLIKELY(elem == nullptr)) {
1137  return InvalidHPackIndexError(index,
1139  }
1140  auto value = ParseValueString(elem->is_binary_header());
1141  if (GPR_UNLIKELY(!value.has_value())) return {};
1142  return elem->WithNewValue(
1143  value->Take(), [=](absl::string_view error, const Slice& value) {
1144  ReportMetadataParseError(elem->key(), error, value.as_string_view());
1145  });
1146  }
1147 
1148  // Parse a varint index encoded key and a string encoded value
1150  auto index = input_->ParseVarint(offset);
1151  if (GPR_UNLIKELY(!index.has_value())) return {};
1152  return ParseIdxKey(*index);
1153  }
1154 
1155  // Parse a string, figuring out if it's binary or not by the key name.
1157  if (is_binary) {
1158  return String::ParseBinary(input_);
1159  } else {
1160  return String::Parse(input_);
1161  }
1162  }
1163 
1164  // Emit an indexed field
1166  *dynamic_table_updates_allowed_ = 0;
1167  if (!index.has_value()) return false;
1168  const auto* elem = table_->Lookup(*index);
1169  if (GPR_UNLIKELY(elem == nullptr)) {
1170  return InvalidHPackIndexError(*index, false);
1171  }
1173  return FinishHeaderOmitFromTable(*elem);
1174  }
1175 
1176  // finish parsing a max table size change
1178  if (!size.has_value()) return false;
1179  if (*dynamic_table_updates_allowed_ == 0) {
1180  return input_->MaybeSetErrorAndReturn(
1181  [] {
1183  "More than two max table size changes in a single frame");
1184  },
1185  false);
1186  }
1187  (*dynamic_table_updates_allowed_)--;
1188  grpc_error_handle err = table_->SetCurrentTableSize(*size);
1189  if (!GRPC_ERROR_IS_NONE(err)) {
1190  input_->SetError(err);
1191  return false;
1192  }
1193  return true;
1194  }
1195 
1196  // Set an invalid hpack index error if no error has been set. Returns result
1197  // unmodified.
1198  template <typename R>
1200  return input_->MaybeSetErrorAndReturn(
1201  [this, index] {
1202  return grpc_error_set_int(
1204  "Invalid HPACK index received"),
1206  static_cast<intptr_t>(index)),
1208  static_cast<intptr_t>(this->table_->num_entries()));
1209  },
1210  std::move(result));
1211  }
1212 
1216  "received initial metadata size exceeds limit (%" PRIu32
1217  " vs. %" PRIu32
1218  "). GRPC_ARG_MAX_METADATA_SIZE can be set to increase this limit.",
1219  *frame_length_, metadata_size_limit_);
1220  if (metadata_buffer_ != nullptr) metadata_buffer_->Clear();
1221  return input_->MaybeSetErrorAndReturn(
1222  [] {
1223  return grpc_error_set_int(
1225  "received initial metadata size exceeds limit"),
1227  },
1228  false);
1229  }
1230 
1234  gpr_log(
1235  GPR_ERROR, "Error parsing metadata: %s",
1236  absl::StrCat("error=", error, " key=", key, " value=", value).c_str());
1237  }
1238 
1239  Input* const input_;
1246 };
1247 
1248 Slice HPackParser::String::Take() {
1249  if (auto* p = absl::get_if<Slice>(&value_)) {
1250  return p->Copy();
1251  } else if (auto* p = absl::get_if<absl::Span<const uint8_t>>(&value_)) {
1252  return Slice::FromCopiedBuffer(*p);
1253  } else if (auto* p = absl::get_if<std::vector<uint8_t>>(&value_)) {
1254  return Slice::FromCopiedBuffer(*p);
1255  }
1256  GPR_UNREACHABLE_CODE(return Slice());
1257 }
1258 
1259 /* PUBLIC INTERFACE */
1260 
1261 HPackParser::HPackParser() = default;
1262 
1263 HPackParser::~HPackParser() = default;
1264 
1265 void HPackParser::BeginFrame(grpc_metadata_batch* metadata_buffer,
1266  uint32_t metadata_size_limit, Boundary boundary,
1267  Priority priority, LogInfo log_info) {
1268  metadata_buffer_ = metadata_buffer;
1269  boundary_ = boundary;
1270  priority_ = priority;
1271  dynamic_table_updates_allowed_ = 2;
1272  frame_length_ = 0;
1273  metadata_size_limit_ = metadata_size_limit;
1274  log_info_ = log_info;
1275 }
1276 
1278  if (GPR_UNLIKELY(!unparsed_bytes_.empty())) {
1279  std::vector<uint8_t> buffer = std::move(unparsed_bytes_);
1280  buffer.insert(buffer.end(), GRPC_SLICE_START_PTR(slice),
1282  return ParseInput(
1283  Input(nullptr, buffer.data(), buffer.data() + buffer.size()), is_last);
1284  }
1285  return ParseInput(Input(slice.refcount, GRPC_SLICE_START_PTR(slice),
1287  is_last);
1288 }
1289 
1290 grpc_error_handle HPackParser::ParseInput(Input input, bool is_last) {
1291  if (ParseInputInner(&input)) {
1292  return GRPC_ERROR_NONE;
1293  }
1294  if (input.eof_error()) {
1295  if (GPR_UNLIKELY(is_last && is_boundary())) {
1297  "Incomplete header at the end of a header/continuation sequence");
1298  }
1299  unparsed_bytes_ = std::vector<uint8_t>(input.frontier(), input.end_ptr());
1300  return GRPC_ERROR_NONE;
1301  }
1302  return input.TakeError();
1303 }
1304 
1305 bool HPackParser::ParseInputInner(Input* input) {
1306  switch (priority_) {
1307  case Priority::None:
1308  break;
1309  case Priority::Included: {
1310  if (input->remaining() < 5) return input->UnexpectedEOF(false);
1311  input->Advance(5);
1312  input->UpdateFrontier();
1314  }
1315  }
1316  while (!input->end_of_stream()) {
1317  if (GPR_UNLIKELY(!Parser(input, metadata_buffer_, metadata_size_limit_,
1318  &table_, &dynamic_table_updates_allowed_,
1319  &frame_length_, log_info_)
1320  .Parse())) {
1321  return false;
1322  }
1323  input->UpdateFrontier();
1324  }
1325  return true;
1326 }
1327 
1328 void HPackParser::FinishFrame() { metadata_buffer_ = nullptr; }
1329 
1330 } // namespace grpc_core
1331 
1332 // TODO(ctiller): this serves as an eviction notice for the remainder of this
1333 // file... it belongs elsewhere!
1334 
1336  grpc_chttp2_stream* s);
1340 
1341 static void force_client_rst_stream(void* sp, grpc_error_handle /*error*/) {
1342  grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(sp);
1343  grpc_chttp2_transport* t = s->t;
1344  if (!s->write_closed) {
1346  &s->stats.outgoing);
1349  }
1350  GRPC_CHTTP2_STREAM_UNREF(s, "final_rst");
1351 }
1352 
1355  grpc_chttp2_stream* s,
1356  const grpc_slice& slice,
1357  int is_last) {
1358  GPR_TIMER_SCOPE("grpc_chttp2_header_parser_parse", 0);
1359  auto* parser = static_cast<grpc_core::HPackParser*>(hpack_parser);
1360  if (s != nullptr) {
1361  s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice);
1362  }
1363  grpc_error_handle error = parser->Parse(slice, is_last != 0);
1364  if (!GRPC_ERROR_IS_NONE(error)) {
1365  return error;
1366  }
1367  if (is_last) {
1368  /* need to check for null stream: this can occur if we receive an invalid
1369  stream id on a header */
1370  if (s != nullptr) {
1371  if (parser->is_boundary()) {
1372  if (s->header_frames_received == 2) {
1374  "Too many trailer frames");
1375  }
1376  s->published_metadata[s->header_frames_received] =
1378  maybe_complete_funcs[s->header_frames_received](t, s);
1379  s->header_frames_received++;
1380  }
1381  if (parser->is_eof()) {
1382  if (t->is_client && !s->write_closed) {
1383  /* server eof ==> complete closure; we may need to forcefully close
1384  the stream. Wait until the combiner lock is ready to be released
1385  however -- it might be that we receive a RST_STREAM following this
1386  and can avoid the extra write */
1387  GRPC_CHTTP2_STREAM_REF(s, "final_rst");
1388  t->combiner->FinallyRun(
1390  GRPC_ERROR_NONE);
1391  }
1392  grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE);
1393  }
1394  }
1395  parser->FinishFrame();
1396  }
1397  return GRPC_ERROR_NONE;
1398 }
grpc_core::HPackParser::LogInfo
Definition: hpack_parser.h:59
trace.h
grpc_core::HPackParser::Parser::SkipPriority
bool SkipPriority()
Definition: hpack_parser.cc:950
grpc_chttp2_maybe_complete_recv_trailing_metadata
void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: chttp2_transport.cc:2025
grpc_core::HPackParser::Parser::LogHeader
void GPR_ATTRIBUTE_NOINLINE LogHeader(const HPackTable::Memento &memento)
Definition: hpack_parser.cc:1053
slice.h
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
grpc_core::HPackParser::Parser::EmitHeader
bool EmitHeader(const HPackTable::Memento &md)
Definition: hpack_parser.cc:1070
GRPC_HPACK_CONSTEXPR_VALUE
#define GRPC_HPACK_CONSTEXPR_VALUE
Definition: hpack_parser.cc:67
priority_
RefCountedPtr< ChildPriority > priority_
Definition: priority.cc:189
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
grpc_core::HPackParser::Priority
Priority
Definition: hpack_parser.h:52
grpc_slice::refcount
struct grpc_slice_refcount * refcount
Definition: include/grpc/impl/codegen/slice.h:66
priority
int priority
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:286
grpc_core::MetadataMap::Parse
static ParsedMetadata< Derived > Parse(absl::string_view key, Slice value, uint32_t transport_size, MetadataParseErrorFn on_error)
Definition: metadata_batch.h:1142
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
grpc_core::emit_sub_tbl
static const int16_t emit_sub_tbl[249 *16]
Definition: hpack_parser.cc:178
timers.h
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
internal.h
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
GPR_TIMER_SCOPE
#define GPR_TIMER_SCOPE(tag, important)
Definition: src/core/lib/profiling/timers.h:43
grpc_core::HPackParser::Input::MaybeSetErrorAndReturn
GPR_ATTRIBUTE_NOINLINE T MaybeSetErrorAndReturn(F error_factory, T return_value)
Definition: hpack_parser.cc:615
parsed_metadata.h
absl::Span
Definition: abseil-cpp/absl/types/span.h:152
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::Slice
Definition: src/core/lib/slice/slice.h:282
GRPC_ERROR_INT_INDEX
@ GRPC_ERROR_INT_INDEX
context sensitive index associated with the error
Definition: error.h:73
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::HPackParser::Parser::Parse
bool Parse()
Definition: hpack_parser.cc:956
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
error
grpc_error_handle error
Definition: retry_filter.cc:499
testing::internal::kBase64
static constexpr char kBase64[]
Definition: googletest/googlemock/src/gmock-internal-utils.cc:223
grpc_core::HPackParser::Parser::InvalidHPackIndexError
R InvalidHPackIndexError(uint32_t index, R result)
Definition: hpack_parser.cc:1199
error_ref_leak.err
err
Definition: error_ref_leak.py:35
grpc_core::HPackParser::Input::remaining
size_t remaining() const
Definition: hpack_parser.cc:490
grpc_core::HPackParser::Parser::log_info_
const LogInfo log_info_
Definition: hpack_parser.cc:1245
closure.h
grpc_core::HPackParser
Definition: hpack_parser.h:40
grpc_chttp2_maybe_complete_recv_initial_metadata
void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: chttp2_transport.cc:1934
grpc_core::emit_tbl
static const uint16_t emit_tbl[256]
Definition: hpack_parser.cc:156
grpc_core::ParsedMetadata::DebugString
std::string DebugString() const
Definition: parsed_metadata.h:199
GRPC_CHTTP2_STREAM_UNREF
#define GRPC_CHTTP2_STREAM_UNREF(stream, reason)
Definition: src/core/ext/transport/chttp2/transport/internal.h:700
GRPC_HPACK_CONSTEXPR_FN
#define GRPC_HPACK_CONSTEXPR_FN
Definition: hpack_parser.cc:66
grpc_core::HPackParser::String::Parse
static absl::optional< String > Parse(Input *input)
Definition: hpack_parser.cc:699
xds_manager.p
p
Definition: xds_manager.py:60
GRPC_CLOSURE_CREATE
#define GRPC_CLOSURE_CREATE(cb, cb_arg, scheduler)
Definition: closure.h:160
grpc_core::HPackParser::String::ParseUncompressed
static absl::optional< String > ParseUncompressed(Input *input, uint32_t length)
Definition: hpack_parser.cc:808
GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM
@ GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM
Definition: src/core/ext/transport/chttp2/transport/internal.h:129
grpc_core::HPackParser::Parser::FinishHeaderOmitFromTable
bool FinishHeaderOmitFromTable(const HPackTable::Memento &md)
Definition: hpack_parser.cc:1106
GRPC_STATUS_RESOURCE_EXHAUSTED
@ GRPC_STATUS_RESOURCE_EXHAUSTED
Definition: include/grpc/impl/codegen/status.h:76
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_core::HPackParser::Input::UpdateFrontier
void UpdateFrontier()
Definition: hpack_parser.cc:633
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
slice_refcount_base.h
grpc_core::HPackParser::String::Take
Slice Take()
Definition: hpack_parser.cc:1248
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_core::HPackParser::Parser::table_
HPackTable *const table_
Definition: hpack_parser.cc:1241
stats.h
grpc_chttp2_stream
Definition: src/core/ext/transport/chttp2/transport/internal.h:456
grpc_core::HPackParser::String::String
String(absl::Span< const uint8_t > v)
Definition: hpack_parser.cc:769
input_
const uint8_t * input_
Definition: json_reader.cc:120
status.h
grpc_core::HPackParser::Boundary
Boundary
Definition: hpack_parser.h:43
grpc_core::HPackParser::Input::ParseVarint
absl::optional< uint32_t > ParseVarint(uint32_t value)
Definition: hpack_parser.cc:518
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_core::HPackParser::Input::end_of_stream
bool end_of_stream() const
Definition: hpack_parser.cc:488
frame_length
static size_t frame_length(size_t payload_length)
Definition: frame_handler_test.cc:42
refcount
size_t refcount
Definition: abseil-cpp/absl/strings/internal/cordz_info.cc:122
grpc_core::HPackParser::Parser::metadata_buffer_
grpc_metadata_batch *const metadata_buffer_
Definition: hpack_parser.cc:1240
grpc_core::HPackParser::Parser::FinishIndexed
bool FinishIndexed(absl::optional< uint32_t > index)
Definition: hpack_parser.cc:1165
hpack_parser.h
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
int16_t
signed short int16_t
Definition: stdint-msvc2008.h:76
grpc_core::HPackParser::Parser::frame_length_
uint32_t *const frame_length_
Definition: hpack_parser.cc:1243
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
grpc_core::HPackParser::Input::cur_ptr
const uint8_t * cur_ptr() const
Definition: hpack_parser.cc:492
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
grpc_core::HPackParser::Input::end_ptr
const uint8_t * end_ptr() const
Definition: hpack_parser.cc:494
grpc_core::HPackParser::String
Definition: hpack_parser.cc:668
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
GPR_UNLIKELY
#define GPR_UNLIKELY(x)
Definition: impl/codegen/port_platform.h:770
absl::get_if
constexpr absl::add_pointer_t< variant_alternative_t< I, variant< Types... > > > get_if(variant< Types... > *v) noexcept
Definition: abseil-cpp/absl/types/variant.h:372
GRPC_STATS_INC_HPACK_RECV_INDEXED
#define GRPC_STATS_INC_HPACK_RECV_INDEXED()
Definition: stats_data.h:310
grpc_slice_refcount
Definition: slice_refcount_base.h:25
GRPC_ERROR_INT_SIZE
@ GRPC_ERROR_INT_SIZE
context sensitive size associated with the error
Definition: error.h:75
grpc_core::HPackParser::Input::StringPrefix::huff
bool huff
Definition: hpack_parser.cc:571
bits
OPENSSL_EXPORT ASN1_BIT_STRING * bits
Definition: x509v3.h:482
absl::optional< uint8_t >
grpc_core::HPackParser::Input::frontier
const uint8_t * frontier() const
Definition: hpack_parser.cc:636
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc_core::HPackParser::Parser::metadata_size_limit_
const uint32_t metadata_size_limit_
Definition: hpack_parser.cc:1244
grpc_core::HPackParser::Input::ParseStringPrefix
absl::optional< StringPrefix > ParseStringPrefix()
Definition: hpack_parser.cc:575
grpc_core::HPackParser::Parser::FinishHeaderOmitFromTable
bool FinishHeaderOmitFromTable(absl::optional< HPackTable::Memento > md)
Definition: hpack_parser.cc:1100
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_core::HPackParser::Parser::HandleMetadataSizeLimitExceeded
GPR_ATTRIBUTE_NOINLINE bool HandleMetadataSizeLimitExceeded(const HPackTable::Memento &)
Definition: hpack_parser.cc:1214
grpc_core::HPackParser::Input::ParseVarintOutOfRange
absl::optional< uint32_t > ParseVarintOutOfRange(uint32_t value, uint8_t last_byte)
Definition: hpack_parser.cc:640
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
grpc_core::hpack_constants::kEntryOverhead
static constexpr uint32_t kEntryOverhead
Definition: hpack_constants.h:25
grpc_core::HPackParser::Input::Input
Input(grpc_slice_refcount *current_slice_refcount, const uint8_t *begin, const uint8_t *end)
Definition: hpack_parser.cc:476
absl::flags_internal::Parse
bool Parse(FlagOpFn op, absl::string_view text, void *dst, std::string *error)
Definition: abseil-cpp/absl/flags/internal/flag.h:125
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
grpc_core::HPackParser::Input::error_
grpc_error_handle error_
Definition: hpack_parser.cc:661
grpc_core::HPackParser::Input::Next
absl::optional< uint8_t > Next()
Definition: hpack_parser.cc:509
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
grpc_core::HPackParser::Input::Advance
void Advance(size_t n)
Definition: hpack_parser.cc:496
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
GPR_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
Definition: impl/codegen/port_platform.h:652
GRPC_SLICE_END_PTR
#define GRPC_SLICE_END_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:110
grpc_core::HPackParser::String::ParseBinary
static absl::optional< String > ParseBinary(Input *input)
Definition: hpack_parser.cc:714
GRPC_METADATA_PUBLISHED_FROM_WIRE
@ GRPC_METADATA_PUBLISHED_FROM_WIRE
Definition: src/core/ext/transport/chttp2/transport/internal.h:452
grpc_core::HPackParser::Input::current_slice_refcount_
grpc_slice_refcount * current_slice_refcount_
Definition: hpack_parser.cc:653
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
grpc_core::HPackParser::Parser::FinishHeaderAndAddToTable
bool FinishHeaderAndAddToTable(absl::optional< HPackTable::Memento > md)
Definition: hpack_parser.cc:1082
setup.idx
idx
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
grpc_core::HPackParser::Input::eof_error
bool eof_error() const
Definition: hpack_parser.cc:592
GRPC_ERROR_CREATE_FROM_STATIC_STRING
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc)
Definition: error.h:291
grpc_core::ParsedMetadata< grpc_metadata_batch >
GRPC_STATS_INC_HPACK_RECV_HUFFMAN
#define GRPC_STATS_INC_HPACK_RECV_HUFFMAN()
Definition: stats_data.h:326
grpc_core::HPackParser::String::String
String(grpc_slice_refcount *r, const uint8_t *begin, const uint8_t *end)
Definition: hpack_parser.cc:770
grpc_core::HPackTable
Definition: hpack_parser_table.h:36
GRPC_SLICE_LENGTH
#define GRPC_SLICE_LENGTH(slice)
Definition: include/grpc/impl/codegen/slice.h:104
grpc_core::HPackParser::Parser::Parser
Parser(Input *input, grpc_metadata_batch *metadata_buffer, uint32_t metadata_size_limit, HPackTable *table, uint8_t *dynamic_table_updates_allowed, uint32_t *frame_length, LogInfo log_info)
Definition: hpack_parser.cc:937
add
static void add(const char *beg, const char *end, char ***ss, size_t *ns)
Definition: debug/trace.cc:96
grpc_core::next_tbl
static const uint8_t next_tbl[256]
Definition: hpack_parser.cc:79
emit
nibblelut emit
Definition: gen_hpack_tables.cc:88
grpc_core::HPackParser::Input::UnexpectedEOF
T UnexpectedEOF(T return_value)
Definition: hpack_parser.cc:626
value_
int value_
Definition: orphanable_test.cc:38
grpc_core::HPackParser::Parser::input_
Input *const input_
Definition: hpack_parser.cc:1239
value
const char * value
Definition: hpack_parser_table.cc:165
grpc_core::HPackParser::Parser::dynamic_table_updates_allowed_
uint8_t *const dynamic_table_updates_allowed_
Definition: hpack_parser.cc:1242
memory_diff.cur
def cur
Definition: memory_diff.py:83
grpc_core::HPackParser::Input::StringPrefix::length
uint32_t length
Definition: hpack_parser.cc:569
grpc_core::HPackParser::String::operator=
String & operator=(String &&other) noexcept
Definition: hpack_parser.cc:675
grpc_core::HPackParser::Input::frontier_
const uint8_t * frontier_
Definition: hpack_parser.cc:659
grpc_core::HPackParser::String::ParseHuff
static bool ParseHuff(Input *input, uint32_t length, Out output)
Definition: hpack_parser.cc:776
benchmark.md
md
Definition: benchmark.py:86
resolver_component_tests_runner.None
None
Definition: resolver_component_tests_runner.py:28
key
const char * key
Definition: hpack_parser_table.cc:164
GRPC_CHTTP2_STREAM_REF
#define GRPC_CHTTP2_STREAM_REF(stream, reason)
Definition: src/core/ext/transport/chttp2/transport/internal.h:698
grpc_core::next_sub_tbl
static const int16_t next_sub_tbl[48 *16]
Definition: hpack_parser.cc:97
grpc_core::grpc_trace_chttp2_hpack_parser
TraceFlag grpc_trace_chttp2_hpack_parser(false, "chttp2_hpack_parser")
grpc_error_set_int
grpc_error_handle grpc_error_set_int(grpc_error_handle src, grpc_error_ints which, intptr_t value)
Definition: error.cc:613
grpc_core::HPackParser::Parser::ParseLiteralKey
absl::optional< HPackTable::Memento > ParseLiteralKey()
Definition: hpack_parser.cc:1115
table_
Vec< int32_t > table_
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:210
maybe_complete_func_type
void(* maybe_complete_func_type)(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: hpack_parser.cc:1335
grpc_core::HPackParser::Input::TakeError
grpc_error_handle TakeError()
Definition: hpack_parser.cc:595
grpc_core::HPackParser::Input::slice_refcount
grpc_slice_refcount * slice_refcount()
Definition: hpack_parser.cc:485
grpc_core::HPackParser::Parser::FinishMaxTableSize
bool FinishMaxTableSize(absl::optional< uint32_t > size)
Definition: hpack_parser.cc:1177
grpc_chttp2_initiate_write
void grpc_chttp2_initiate_write(grpc_chttp2_transport *t, grpc_chttp2_initiate_write_reason reason)
Definition: chttp2_transport.cc:891
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
GRPC_ERROR_CREATE_FROM_CPP_STRING
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc)
Definition: error.h:297
GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED
#define GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED()
Definition: stats_data.h:324
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
hpack_constants.h
fix_build_deps.r
r
Definition: fix_build_deps.py:491
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
string_view
absl::string_view string_view
Definition: attr.cc:22
grpc_core::HPackParser::Input::StringPrefix
Definition: hpack_parser.cc:567
grpc_trace_chttp2_hpack_parser
grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_hpack_parser
combiner.h
grpc_core::HPackParser::String::operator=
String & operator=(const String &)=delete
http2_errors.h
grpc_chttp2_transport
Definition: src/core/ext/transport/chttp2/transport/internal.h:238
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc_core::HPackParser::String::String
String(const String &)=delete
grpc_chttp2_mark_stream_closed
void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport *t, grpc_chttp2_stream *s, int close_reads, int close_writes, grpc_error_handle error)
Definition: chttp2_transport.cc:2193
GRPC_ERROR_UNREF
#define GRPC_ERROR_UNREF(err)
Definition: error.h:262
grpc_core::HPackParser::String::String
String(std::vector< uint8_t > v)
Definition: hpack_parser.cc:768
transport.h
grpc_chttp2_add_rst_stream_to_next_write
void grpc_chttp2_add_rst_stream_to_next_write(grpc_chttp2_transport *t, uint32_t id, uint32_t code, grpc_transport_one_way_stats *stats)
Definition: frame_rst_stream.cc:67
grpc_core::HPackParser::Input::SetError
GPR_ATTRIBUTE_NOINLINE void SetError(grpc_error_handle error)
Definition: hpack_parser.cc:603
input
std::string input
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:197
grpc_core::HPackParser::String::String
String(String &&other) noexcept
Definition: hpack_parser.cc:672
grpc_core::HPackParser::Input
Definition: hpack_parser.cc:474
grpc_core::HPackParser::Parser::ParseVarIdxKey
absl::optional< HPackTable::Memento > ParseVarIdxKey(uint32_t offset)
Definition: hpack_parser.cc:1149
GPR_DEBUG
#define GPR_DEBUG
Definition: include/grpc/impl/codegen/log.h:55
table
uint8_t table[256]
Definition: hpack_parser.cc:456
grpc_core::HPackParser::Parser::ReportMetadataParseError
static void ReportMetadataParseError(absl::string_view key, absl::string_view error, absl::string_view value)
Definition: hpack_parser.cc:1231
grpc_core::HPackParser::Parser::ParseValueString
absl::optional< String > ParseValueString(bool is_binary)
Definition: hpack_parser.cc:1156
grpc_core::HPackParser::String::value_
absl::variant< Slice, absl::Span< const uint8_t >, std::vector< uint8_t > > value_
Definition: hpack_parser.cc:931
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
grpc_core::HPackParser::Input::eof_error_
bool eof_error_
Definition: hpack_parser.cc:663
grpc_error
Definition: error_internal.h:42
grpc_core::HPackParser::Input::end_
const uint8_t *const end_
Definition: hpack_parser.cc:657
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
grpc_core::HPackParser::String::string_view
absl::string_view string_view() const
Definition: hpack_parser.cc:685
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
grpc_metadata_batch
Definition: metadata_batch.h:1259
grpc_core::HPackParser::String::Unbase64
static absl::optional< String > Unbase64(Input *input, String s)
Definition: hpack_parser.cc:827
ABSL_FALLTHROUGH_INTENDED
#define ABSL_FALLTHROUGH_INTENDED
Definition: abseil-cpp/absl/base/attributes.h:641
frame_rst_stream.h
force_client_rst_stream
static void force_client_rst_stream(void *sp, grpc_error_handle)
Definition: hpack_parser.cc:1341
grpc_core::HPackParser::String::Unbase64Loop
static absl::optional< std::vector< uint8_t > > Unbase64Loop(const uint8_t *cur, const uint8_t *end)
Definition: hpack_parser.cc:850
grpc_core::HPackParser::Input::begin_
const uint8_t * begin_
Definition: hpack_parser.cc:655
grpc_core::HPackParser::Parser::ParseIdxKey
absl::optional< HPackTable::Memento > ParseIdxKey(uint32_t index)
Definition: hpack_parser.cc:1134
GRPC_HTTP2_NO_ERROR
@ GRPC_HTTP2_NO_ERROR
Definition: http2_errors.h:24
maybe_complete_funcs
static const maybe_complete_func_type maybe_complete_funcs[]
Definition: hpack_parser.cc:1337
absl::EndsWith
bool EndsWith(absl::string_view text, absl::string_view suffix) noexcept
Definition: third_party/abseil-cpp/absl/strings/match.h:68
GPR_ATTRIBUTE_NOINLINE
#define GPR_ATTRIBUTE_NOINLINE
Definition: impl/codegen/port_platform.h:684
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
GRPC_ERROR_INT_GRPC_STATUS
@ GRPC_ERROR_INT_GRPC_STATUS
grpc status code representing this error
Definition: error.h:66
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
grpc_core::HPackParser::Input::peek
absl::optional< uint8_t > peek() const
Definition: hpack_parser.cc:500
grpc_core::HPackParser::Parser
Definition: hpack_parser.cc:935
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241
port_platform.h
grpc_chttp2_header_parser_parse
grpc_error_handle grpc_chttp2_header_parser_parse(void *hpack_parser, grpc_chttp2_transport *t, grpc_chttp2_stream *s, const grpc_slice &slice, int is_last)
Definition: hpack_parser.cc:1353


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:13