blob: 09ec66d675b4cebe35ad17faaafae3e722da5ecc [file] [log] [blame]
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +01001/*
2 * QPACK decompressor
3 *
Willy Tarreau3dfb7da2022-03-02 22:33:39 +01004 * Copyright 2021 HAProxy Technologies, Frederic Lecaille <flecaille@haproxy.com>
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +01005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation, version 2.1
9 * exclusively.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <inttypes.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include <import/ist.h>
27#include <haproxy/buf.h>
28#include <haproxy/chunk.h>
29#include <haproxy/h3.h>
30#include <haproxy/qpack-t.h>
31#include <haproxy/qpack-dec.h>
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +020032#include <haproxy/qpack-tbl.h>
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +010033#include <haproxy/hpack-huff.h>
34#include <haproxy/hpack-tbl.h>
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +020035#include <haproxy/http-hdr.h>
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +010036#include <haproxy/tools.h>
37
Amaury Denoyelled96361b2022-03-25 14:56:51 +010038#if defined(DEBUG_QPACK)
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +010039#define qpack_debug_printf fprintf
40#define qpack_debug_hexdump debug_hexdump
41#else
42#define qpack_debug_printf(...) do { } while (0)
43#define qpack_debug_hexdump(...) do { } while (0)
44#endif
45
46/* Encoded field line bitmask */
47#define QPACK_EFL_BITMASK 0xf0
48#define QPACK_LFL_WPBNM 0x00 // Literal field line with post-base name reference
49#define QPACK_IFL_WPBI 0x10 // Indexed field line with post-based index
50#define QPACK_LFL_WLN_BIT 0x20 // Literal field line with literal name
51#define QPACK_LFL_WNR_BIT 0x40 // Literal field line with name reference
52#define QPACK_IFL_BIT 0x80 // Indexed field line
53
54/* reads a varint from <raw>'s lowest <b> bits and <len> bytes max (raw included).
55 * returns the 64-bit value on success after updating buf and len_in. Forces
56 * len_in to (uint64_t)-1 on truncated input.
57 * Note that this function is similar to the one used for HPACK (except that is supports
58 * up to 62-bits integers).
59 */
60static uint64_t qpack_get_varint(const unsigned char **buf, uint64_t *len_in, int b)
61{
62 uint64_t ret = 0;
63 int len = *len_in;
64 const uint8_t *raw = *buf;
65 uint8_t shift = 0;
66
67 len--;
Frédéric Lécaille68424852022-02-02 14:56:23 +010068 ret = *raw++ & ((1ULL << b) - 1);
69 if (ret != (uint64_t)((1ULL << b) - 1))
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +010070 goto end;
71
72 while (len && (*raw & 128)) {
73 ret += ((uint64_t)*raw++ & 127) << shift;
74 shift += 7;
75 len--;
76 }
77
78 /* last 7 bits */
79 if (!len)
80 goto too_short;
81
82 len--;
83 ret += ((uint64_t)*raw++ & 127) << shift;
84
85 end:
86 *buf = raw;
87 *len_in = len;
88 return ret;
89
90 too_short:
91 *len_in = (uint64_t)-1;
92 return 0;
93}
94
Amaury Denoyelle5869cb62022-05-31 15:21:27 +020095/* Decode an encoder stream.
96 *
97 * Returns 0 on success else non-zero.
98 */
Amaury Denoyelle53eef462022-06-14 16:34:32 +020099int qpack_decode_enc(struct buffer *buf, void *ctx)
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100100{
101 size_t len;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100102 unsigned char inst;
103
Amaury Denoyelle53eef462022-06-14 16:34:32 +0200104 len = b_data(buf);
105 qpack_debug_hexdump(stderr, "[QPACK-DEC-ENC] ", b_head(buf), 0, len);
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100106
107 if (!len) {
108 qpack_debug_printf(stderr, "[QPACK-DEC-ENC] empty stream\n");
109 return 0;
110 }
111
Amaury Denoyelle53eef462022-06-14 16:34:32 +0200112 inst = (unsigned char)*b_head(buf) & QPACK_ENC_INST_BITMASK;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100113 if (inst == QPACK_ENC_INST_DUP) {
114 /* Duplicate */
115 }
116 else if (inst & QPACK_ENC_INST_IWNR_BIT) {
117 /* Insert With Name Reference */
118 }
119 else if (inst & QPACK_ENC_INST_IWLN_BIT) {
120 /* Insert with literal name */
121 }
122 else if (inst & QPACK_ENC_INST_SDTC_BIT) {
123 /* Set dynamic table capacity */
124 }
125
Amaury Denoyelle5869cb62022-05-31 15:21:27 +0200126 return 0;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100127}
128
Amaury Denoyelle5869cb62022-05-31 15:21:27 +0200129/* Decode an decoder stream.
130 *
131 * Returns 0 on success else non-zero.
132 */
Amaury Denoyelle53eef462022-06-14 16:34:32 +0200133int qpack_decode_dec(struct buffer *buf, void *ctx)
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100134{
135 size_t len;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100136 unsigned char inst;
137
Amaury Denoyelle53eef462022-06-14 16:34:32 +0200138 len = b_data(buf);
139 qpack_debug_hexdump(stderr, "[QPACK-DEC-DEC] ", b_head(buf), 0, len);
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100140
141 if (!len) {
142 qpack_debug_printf(stderr, "[QPACK-DEC-DEC] empty stream\n");
143 return 0;
144 }
145
Amaury Denoyelle53eef462022-06-14 16:34:32 +0200146 inst = (unsigned char)*b_head(buf) & QPACK_DEC_INST_BITMASK;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100147 if (inst == QPACK_DEC_INST_ICINC) {
148 /* Insert count increment */
149 }
150 else if (inst & QPACK_DEC_INST_SACK) {
151 /* Section Acknowledgment */
152 }
153 else if (inst & QPACK_DEC_INST_SCCL) {
154 /* Stream cancellation */
155 }
156
Amaury Denoyelle5869cb62022-05-31 15:21:27 +0200157 return 0;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100158}
159
160/* Decode a field section prefix made of <enc_ric> and <db> two varints.
161 * Also set the 'S' sign bit for <db>.
162 * Return a negative error if failed, 0 if not.
163 */
164static int qpack_decode_fs_pfx(uint64_t *enc_ric, uint64_t *db, int *sign_bit,
165 const unsigned char **raw, size_t *len)
166{
167 *enc_ric = qpack_get_varint(raw, len, 8);
168 if (*len == (uint64_t)-1)
169 return -QPACK_ERR_RIC;
170
171 *sign_bit = **raw & 0x8;
172 *db = qpack_get_varint(raw, len, 7);
173 if (*len == (uint64_t)-1)
174 return -QPACK_ERR_DB;
175
176 return 0;
177}
178
Amaury Denoyellec5d31ed2022-06-14 17:34:53 +0200179/* Decode a field section from the <raw> buffer of <len> bytes. Each parsed
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +0200180 * header is inserted into <list> of <list_size> entries max and uses <tmp> as
181 * a storage for some elements pointing into it. An end marker is inserted at
182 * the end of the list with empty strings as name/value.
Amaury Denoyellec5d31ed2022-06-14 17:34:53 +0200183 *
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200184 * Returns the number of headers inserted into list excluding the end marker.
185 * In case of error, a negative code QPACK_ERR_* is returned.
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100186 */
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200187int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp,
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +0200188 struct http_hdr *list, int list_size)
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100189{
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200190 struct ist name, value;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100191 uint64_t enc_ric, db;
192 int s;
193 unsigned int efl_type;
194 int ret;
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200195 int hdr_idx = 0;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100196
197 qpack_debug_hexdump(stderr, "[QPACK-DEC-FS] ", (const char *)raw, 0, len);
198
Amaury Denoyellec5d31ed2022-06-14 17:34:53 +0200199 /* parse field section prefix */
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100200 ret = qpack_decode_fs_pfx(&enc_ric, &db, &s, &raw, &len);
201 if (ret < 0) {
202 qpack_debug_printf(stderr, "##ERR@%d(%d)\n", __LINE__, ret);
203 goto out;
204 }
205
206 chunk_reset(tmp);
207 qpack_debug_printf(stderr, "enc_ric: %llu db: %llu s=%d\n",
208 (unsigned long long)enc_ric, (unsigned long long)db, !!s);
209 /* Decode field lines */
210 while (len) {
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +0200211 if (hdr_idx >= list_size) {
212 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
213 ret = -QPACK_ERR_TOO_LARGE;
214 goto out;
215 }
216
Amaury Denoyellec5d31ed2022-06-14 17:34:53 +0200217 /* parse field line representation */
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100218 efl_type = *raw & QPACK_EFL_BITMASK;
219 qpack_debug_printf(stderr, "efl_type=0x%02x\n", efl_type);
Amaury Denoyellec5d31ed2022-06-14 17:34:53 +0200220
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100221 if (efl_type == QPACK_LFL_WPBNM) {
Amaury Denoyelle28d3c242022-06-14 16:36:15 +0200222 /* Literal field line with post-base name reference
223 *
224 * TODO not implemented
225 *
226 * For the moment, this should never happen as
227 * currently we do not support dynamic table insertion
228 * and specify an empty table size.
229 */
230#if 0
Amaury Denoyelle18a10d02022-03-25 15:11:38 +0100231 uint64_t index __maybe_unused, length;
Amaury Denoyelled96361b2022-03-25 14:56:51 +0100232 unsigned int n __maybe_unused, h __maybe_unused;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100233
234 qpack_debug_printf(stderr, "literal field line with post-base name reference:");
235 n = *raw & 0x08;
236 index = qpack_get_varint(&raw, &len, 3);
237 if (len == (uint64_t)-1) {
238 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
239 ret = -QPACK_ERR_TRUNCATED;
240 goto out;
241 }
242
243 qpack_debug_printf(stderr, " n=%d index=%llu", !!n, (unsigned long long)index);
244 h = *raw & 0x80;
245 length = qpack_get_varint(&raw, &len, 7);
246 if (len == (uint64_t)-1) {
247 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
248 ret = -QPACK_ERR_TRUNCATED;
249 goto out;
250 }
251
252 qpack_debug_printf(stderr, " h=%d length=%llu", !!h, (unsigned long long)length);
Frédéric Lécaillee629cfd2021-12-15 14:16:16 +0100253
254 if (len < length) {
255 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
256 ret = -QPACK_ERR_TRUNCATED;
257 goto out;
258 }
259
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100260 raw += length;
261 len -= length;
Amaury Denoyelle28d3c242022-06-14 16:36:15 +0200262#endif
263 ABORT_NOW(); /* dynamic table not supported */
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200264 }
265 else if (efl_type == QPACK_IFL_WPBI) {
Amaury Denoyelle28d3c242022-06-14 16:36:15 +0200266 /* Indexed field line with post-base index
267 *
268 * TODO not implemented
269 *
270 * For the moment, this should never happen as
271 * currently we do not support dynamic table insertion
272 * and specify an empty table size.
273 */
274#if 0
Amaury Denoyelle18a10d02022-03-25 15:11:38 +0100275 uint64_t index __maybe_unused;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100276
277 qpack_debug_printf(stderr, "indexed field line with post-base index:");
278 index = qpack_get_varint(&raw, &len, 4);
279 if (len == (uint64_t)-1) {
280 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
281 ret = -QPACK_ERR_TRUNCATED;
282 goto out;
283 }
284
285 qpack_debug_printf(stderr, " index=%llu", (unsigned long long)index);
Amaury Denoyelle28d3c242022-06-14 16:36:15 +0200286#endif
287 ABORT_NOW(); /* dynamic table not supported */
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200288 }
289 else if (efl_type & QPACK_IFL_BIT) {
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100290 /* Indexed field line */
291 uint64_t index;
Amaury Denoyelledebaa042022-06-20 15:47:46 +0200292 unsigned int static_tbl;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100293
294 qpack_debug_printf(stderr, "indexed field line:");
Amaury Denoyelledebaa042022-06-20 15:47:46 +0200295 static_tbl = efl_type & 0x40;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100296 index = qpack_get_varint(&raw, &len, 6);
297 if (len == (uint64_t)-1) {
298 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
299 ret = -QPACK_ERR_TRUNCATED;
300 goto out;
301 }
302
Amaury Denoyelledebaa042022-06-20 15:47:46 +0200303 if (static_tbl) {
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200304 name = qpack_sht[index].n;
305 value = qpack_sht[index].v;
306 }
Amaury Denoyelledebaa042022-06-20 15:47:46 +0200307 else {
308 /* TODO not implemented
309 *
310 * For the moment, this should never happen as
311 * currently we do not support dynamic table insertion
312 * and specify an empty table size.
313 */
314 ABORT_NOW();
315 }
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200316
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100317 qpack_debug_printf(stderr, " t=%d index=%llu", !!t, (unsigned long long)index);
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200318 }
319 else if (efl_type & QPACK_LFL_WNR_BIT) {
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100320 /* Literal field line with name reference */
321 uint64_t index, length;
Amaury Denoyelle18a10d02022-03-25 15:11:38 +0100322 unsigned int t, n __maybe_unused, h;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100323
324 qpack_debug_printf(stderr, "Literal field line with name reference:");
325 n = efl_type & 0x20;
326 t = efl_type & 0x10;
327 index = qpack_get_varint(&raw, &len, 4);
328 if (len == (uint64_t)-1) {
329 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
330 ret = -QPACK_ERR_TRUNCATED;
331 goto out;
332 }
333
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200334 if (t)
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200335 name = qpack_sht[index].n;
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200336
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100337 qpack_debug_printf(stderr, " n=%d t=%d index=%llu", !!n, !!t, (unsigned long long)index);
338 h = *raw & 0x80;
339 length = qpack_get_varint(&raw, &len, 7);
340 if (len == (uint64_t)-1) {
341 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
342 ret = -QPACK_ERR_TRUNCATED;
343 goto out;
344 }
345
346 qpack_debug_printf(stderr, " h=%d length=%llu", !!h, (unsigned long long)length);
347 if (h) {
348 char *trash;
349 int nlen;
350
351 trash = chunk_newstr(tmp);
352 if (!trash) {
353 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
354 ret = -QPACK_DECOMPRESSION_FAILED;
355 goto out;
356 }
357 nlen = huff_dec(raw, length, trash, tmp->size - tmp->data);
358 if (nlen == (uint32_t)-1) {
359 qpack_debug_printf(stderr, " can't decode huffman.\n");
360 ret = -QPACK_ERR_HUFFMAN;
361 goto out;
362 }
363
364 qpack_debug_printf(stderr, " [name huff %d->%d '%s']", (int)length, (int)nlen, trash);
Amaury Denoyelle9c8c4fa2021-09-30 17:14:55 +0200365 /* makes an ist from tmp storage */
366 b_add(tmp, nlen);
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200367 value = ist2(trash, nlen);
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100368 }
Amaury Denoyelle7d3aea52021-11-24 16:04:03 +0100369 else {
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200370 value = ist2(raw, length);
Amaury Denoyelle7d3aea52021-11-24 16:04:03 +0100371 }
372
Frédéric Lécaillee629cfd2021-12-15 14:16:16 +0100373 if (len < length) {
374 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
375 ret = -QPACK_ERR_TRUNCATED;
376 goto out;
377 }
378
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100379 raw += length;
380 len -= length;
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200381 }
382 else if (efl_type & QPACK_LFL_WLN_BIT) {
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100383 /* Literal field line with literal name */
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200384 unsigned int n __maybe_unused, hname, hvalue;
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100385 uint64_t name_len, value_len;
386
387 qpack_debug_printf(stderr, "Literal field line with literal name:");
388 n = *raw & 0x10;
389 hname = *raw & 0x08;
390 name_len = qpack_get_varint(&raw, &len, 3);
391 if (len == (uint64_t)-1) {
392 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
393 ret = -QPACK_ERR_TRUNCATED;
394 goto out;
395 }
396
Amaury Denoyelleab9cec72022-02-14 14:45:10 +0100397 qpack_debug_printf(stderr, " n=%d hname=%d name_len=%llu", !!n, !!hname, (unsigned long long)name_len);
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100398 /* Name string */
Frédéric Lécaillee629cfd2021-12-15 14:16:16 +0100399
400 if (len < name_len) {
401 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
402 ret = -QPACK_ERR_TRUNCATED;
403 goto out;
404 }
405
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200406 if (hname) {
407 char *trash;
408 int nlen;
409
410 trash = chunk_newstr(tmp);
411 if (!trash) {
412 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
413 ret = -QPACK_DECOMPRESSION_FAILED;
414 goto out;
415 }
416 nlen = huff_dec(raw, name_len, trash, tmp->size - tmp->data);
417 if (nlen == (uint32_t)-1) {
418 qpack_debug_printf(stderr, " can't decode huffman.\n");
419 ret = -QPACK_ERR_HUFFMAN;
420 goto out;
421 }
422
423 qpack_debug_printf(stderr, " [name huff %d->%d '%s']", (int)name_len, (int)nlen, trash);
424 /* makes an ist from tmp storage */
425 b_add(tmp, nlen);
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200426 name = ist2(trash, nlen);
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200427 }
428 else {
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200429 name = ist2(raw, name_len);
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200430 }
431
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100432 raw += name_len;
433 len -= name_len;
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200434
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100435 hvalue = *raw & 0x80;
436 value_len = qpack_get_varint(&raw, &len, 7);
437 if (len == (uint64_t)-1) {
438 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
439 ret = -QPACK_ERR_TRUNCATED;
440 goto out;
441 }
442
443 qpack_debug_printf(stderr, " hvalue=%d value_len=%llu", !!hvalue, (unsigned long long)value_len);
444
Frédéric Lécaillee629cfd2021-12-15 14:16:16 +0100445 if (len < value_len) {
446 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
447 ret = -QPACK_ERR_TRUNCATED;
448 goto out;
449 }
450
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200451 if (hvalue) {
452 char *trash;
453 int nlen;
454
455 trash = chunk_newstr(tmp);
456 if (!trash) {
457 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
458 ret = -QPACK_DECOMPRESSION_FAILED;
459 goto out;
460 }
461 nlen = huff_dec(raw, value_len, trash, tmp->size - tmp->data);
462 if (nlen == (uint32_t)-1) {
463 qpack_debug_printf(stderr, " can't decode huffman.\n");
464 ret = -QPACK_ERR_HUFFMAN;
465 goto out;
466 }
467
468 qpack_debug_printf(stderr, " [name huff %d->%d '%s']", (int)value_len, (int)nlen, trash);
469 /* makes an ist from tmp storage */
470 b_add(tmp, nlen);
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200471 value = ist2(trash, nlen);
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200472 }
473 else {
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200474 value = ist2(raw, value_len);
Amaury Denoyelle4bcaf692022-06-14 16:34:55 +0200475 }
476
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100477 raw += value_len;
478 len -= value_len;
479 }
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200480
481 list[hdr_idx].n = name;
482 list[hdr_idx].v = value;
483 ++hdr_idx;
484
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100485 qpack_debug_printf(stderr, "\n");
486 }
487
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +0200488 if (hdr_idx >= list_size) {
489 qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
490 ret = -QPACK_ERR_TOO_LARGE;
491 goto out;
492 }
493
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200494 /* put an end marker */
495 list[hdr_idx].n = list[hdr_idx].v = IST_NULL;
Amaury Denoyelleb666c6b2022-06-14 17:17:07 +0200496 ret = hdr_idx;
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200497
Frédéric Lécailleb4672fb2021-03-03 16:13:10 +0100498 out:
499 qpack_debug_printf(stderr, "-- done: ret=%d\n", ret);
500 return ret;
501}