Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QPACK decompressor |
| 3 | * |
Willy Tarreau | 3dfb7da | 2022-03-02 22:33:39 +0100 | [diff] [blame] | 4 | * Copyright 2021 HAProxy Technologies, Frederic Lecaille <flecaille@haproxy.com> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 5 | * |
| 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> |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 30 | #include <haproxy/ncbuf.h> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 31 | #include <haproxy/qpack-t.h> |
| 32 | #include <haproxy/qpack-dec.h> |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 33 | #include <haproxy/qpack-tbl.h> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 34 | #include <haproxy/hpack-huff.h> |
| 35 | #include <haproxy/hpack-tbl.h> |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 36 | #include <haproxy/http-hdr.h> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 37 | #include <haproxy/tools.h> |
| 38 | |
Amaury Denoyelle | d96361b | 2022-03-25 14:56:51 +0100 | [diff] [blame] | 39 | #if defined(DEBUG_QPACK) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 40 | #define qpack_debug_printf fprintf |
| 41 | #define qpack_debug_hexdump debug_hexdump |
| 42 | #else |
| 43 | #define qpack_debug_printf(...) do { } while (0) |
| 44 | #define qpack_debug_hexdump(...) do { } while (0) |
| 45 | #endif |
| 46 | |
| 47 | /* Encoded field line bitmask */ |
| 48 | #define QPACK_EFL_BITMASK 0xf0 |
| 49 | #define QPACK_LFL_WPBNM 0x00 // Literal field line with post-base name reference |
| 50 | #define QPACK_IFL_WPBI 0x10 // Indexed field line with post-based index |
| 51 | #define QPACK_LFL_WLN_BIT 0x20 // Literal field line with literal name |
| 52 | #define QPACK_LFL_WNR_BIT 0x40 // Literal field line with name reference |
| 53 | #define QPACK_IFL_BIT 0x80 // Indexed field line |
| 54 | |
| 55 | /* reads a varint from <raw>'s lowest <b> bits and <len> bytes max (raw included). |
| 56 | * returns the 64-bit value on success after updating buf and len_in. Forces |
| 57 | * len_in to (uint64_t)-1 on truncated input. |
| 58 | * Note that this function is similar to the one used for HPACK (except that is supports |
| 59 | * up to 62-bits integers). |
| 60 | */ |
| 61 | static uint64_t qpack_get_varint(const unsigned char **buf, uint64_t *len_in, int b) |
| 62 | { |
| 63 | uint64_t ret = 0; |
| 64 | int len = *len_in; |
| 65 | const uint8_t *raw = *buf; |
| 66 | uint8_t shift = 0; |
| 67 | |
| 68 | len--; |
Frédéric Lécaille | 6842485 | 2022-02-02 14:56:23 +0100 | [diff] [blame] | 69 | ret = *raw++ & ((1ULL << b) - 1); |
| 70 | if (ret != (uint64_t)((1ULL << b) - 1)) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 71 | goto end; |
| 72 | |
| 73 | while (len && (*raw & 128)) { |
| 74 | ret += ((uint64_t)*raw++ & 127) << shift; |
| 75 | shift += 7; |
| 76 | len--; |
| 77 | } |
| 78 | |
| 79 | /* last 7 bits */ |
| 80 | if (!len) |
| 81 | goto too_short; |
| 82 | |
| 83 | len--; |
| 84 | ret += ((uint64_t)*raw++ & 127) << shift; |
| 85 | |
| 86 | end: |
| 87 | *buf = raw; |
| 88 | *len_in = len; |
| 89 | return ret; |
| 90 | |
| 91 | too_short: |
| 92 | *len_in = (uint64_t)-1; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | /* Decode an encoder stream */ |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 97 | int qpack_decode_enc(struct qcs *qcs, void *ctx) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 98 | { |
| 99 | size_t len; |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 100 | struct ncbuf *rxbuf; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 101 | unsigned char inst; |
| 102 | |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 103 | rxbuf = &qcs->rx.ncbuf; |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 104 | len = ncb_data(rxbuf, 0); |
| 105 | qpack_debug_hexdump(stderr, "[QPACK-DEC-ENC] ", ncb_head(rxbuf), 0, len); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 106 | |
| 107 | if (!len) { |
| 108 | qpack_debug_printf(stderr, "[QPACK-DEC-ENC] empty stream\n"); |
| 109 | return 0; |
| 110 | } |
| 111 | |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 112 | inst = (unsigned char)*ncb_head(rxbuf) & QPACK_ENC_INST_BITMASK; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 113 | 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 | |
| 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | /* Decode an decoder stream */ |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 130 | int qpack_decode_dec(struct qcs *qcs, void *ctx) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 131 | { |
| 132 | size_t len; |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 133 | struct ncbuf *rxbuf; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 134 | unsigned char inst; |
| 135 | |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 136 | rxbuf = &qcs->rx.ncbuf; |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 137 | len = ncb_data(rxbuf, 0); |
| 138 | qpack_debug_hexdump(stderr, "[QPACK-DEC-DEC] ", ncb_head(rxbuf), 0, len); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 139 | |
| 140 | if (!len) { |
| 141 | qpack_debug_printf(stderr, "[QPACK-DEC-DEC] empty stream\n"); |
| 142 | return 0; |
| 143 | } |
| 144 | |
Amaury Denoyelle | 3db98e9 | 2022-05-13 15:41:04 +0200 | [diff] [blame] | 145 | inst = (unsigned char)*ncb_head(rxbuf) & QPACK_DEC_INST_BITMASK; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 146 | if (inst == QPACK_DEC_INST_ICINC) { |
| 147 | /* Insert count increment */ |
| 148 | } |
| 149 | else if (inst & QPACK_DEC_INST_SACK) { |
| 150 | /* Section Acknowledgment */ |
| 151 | } |
| 152 | else if (inst & QPACK_DEC_INST_SCCL) { |
| 153 | /* Stream cancellation */ |
| 154 | } |
| 155 | |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | /* Decode a field section prefix made of <enc_ric> and <db> two varints. |
| 160 | * Also set the 'S' sign bit for <db>. |
| 161 | * Return a negative error if failed, 0 if not. |
| 162 | */ |
| 163 | static int qpack_decode_fs_pfx(uint64_t *enc_ric, uint64_t *db, int *sign_bit, |
| 164 | const unsigned char **raw, size_t *len) |
| 165 | { |
| 166 | *enc_ric = qpack_get_varint(raw, len, 8); |
| 167 | if (*len == (uint64_t)-1) |
| 168 | return -QPACK_ERR_RIC; |
| 169 | |
| 170 | *sign_bit = **raw & 0x8; |
| 171 | *db = qpack_get_varint(raw, len, 7); |
| 172 | if (*len == (uint64_t)-1) |
| 173 | return -QPACK_ERR_DB; |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* Decode a field section from <len> bytes length <raw> buffer. |
| 179 | * Produces the output into <tmp> buffer. |
| 180 | */ |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 181 | int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp, |
| 182 | struct http_hdr *list) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 183 | { |
| 184 | uint64_t enc_ric, db; |
| 185 | int s; |
| 186 | unsigned int efl_type; |
| 187 | int ret; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 188 | int hdr_idx = 0; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 189 | |
| 190 | qpack_debug_hexdump(stderr, "[QPACK-DEC-FS] ", (const char *)raw, 0, len); |
| 191 | |
| 192 | ret = qpack_decode_fs_pfx(&enc_ric, &db, &s, &raw, &len); |
| 193 | if (ret < 0) { |
| 194 | qpack_debug_printf(stderr, "##ERR@%d(%d)\n", __LINE__, ret); |
| 195 | goto out; |
| 196 | } |
| 197 | |
| 198 | chunk_reset(tmp); |
| 199 | qpack_debug_printf(stderr, "enc_ric: %llu db: %llu s=%d\n", |
| 200 | (unsigned long long)enc_ric, (unsigned long long)db, !!s); |
| 201 | /* Decode field lines */ |
| 202 | while (len) { |
| 203 | qpack_debug_hexdump(stderr, "raw ", (const char *)raw, 0, len); |
| 204 | efl_type = *raw & QPACK_EFL_BITMASK; |
| 205 | qpack_debug_printf(stderr, "efl_type=0x%02x\n", efl_type); |
| 206 | if (efl_type == QPACK_LFL_WPBNM) { |
| 207 | /* Literal field line with post-base name reference */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 208 | uint64_t index __maybe_unused, length; |
Amaury Denoyelle | d96361b | 2022-03-25 14:56:51 +0100 | [diff] [blame] | 209 | unsigned int n __maybe_unused, h __maybe_unused; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 210 | |
| 211 | qpack_debug_printf(stderr, "literal field line with post-base name reference:"); |
| 212 | n = *raw & 0x08; |
| 213 | index = qpack_get_varint(&raw, &len, 3); |
| 214 | if (len == (uint64_t)-1) { |
| 215 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 216 | ret = -QPACK_ERR_TRUNCATED; |
| 217 | goto out; |
| 218 | } |
| 219 | |
| 220 | qpack_debug_printf(stderr, " n=%d index=%llu", !!n, (unsigned long long)index); |
| 221 | h = *raw & 0x80; |
| 222 | length = qpack_get_varint(&raw, &len, 7); |
| 223 | if (len == (uint64_t)-1) { |
| 224 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 225 | ret = -QPACK_ERR_TRUNCATED; |
| 226 | goto out; |
| 227 | } |
| 228 | |
| 229 | qpack_debug_printf(stderr, " h=%d length=%llu", !!h, (unsigned long long)length); |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 230 | |
| 231 | if (len < length) { |
| 232 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 233 | ret = -QPACK_ERR_TRUNCATED; |
| 234 | goto out; |
| 235 | } |
| 236 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 237 | /* XXX Value string XXX */ |
| 238 | raw += length; |
| 239 | len -= length; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 240 | } |
| 241 | else if (efl_type == QPACK_IFL_WPBI) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 242 | /* Indexed field line with post-base index */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 243 | uint64_t index __maybe_unused; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 244 | |
| 245 | qpack_debug_printf(stderr, "indexed field line with post-base index:"); |
| 246 | index = qpack_get_varint(&raw, &len, 4); |
| 247 | if (len == (uint64_t)-1) { |
| 248 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 249 | ret = -QPACK_ERR_TRUNCATED; |
| 250 | goto out; |
| 251 | } |
| 252 | |
| 253 | qpack_debug_printf(stderr, " index=%llu", (unsigned long long)index); |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 254 | } |
| 255 | else if (efl_type & QPACK_IFL_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 256 | /* Indexed field line */ |
| 257 | uint64_t index; |
| 258 | unsigned int t; |
| 259 | |
| 260 | qpack_debug_printf(stderr, "indexed field line:"); |
| 261 | t = efl_type & 0x40; |
| 262 | index = qpack_get_varint(&raw, &len, 6); |
| 263 | if (len == (uint64_t)-1) { |
| 264 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 265 | ret = -QPACK_ERR_TRUNCATED; |
| 266 | goto out; |
| 267 | } |
| 268 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 269 | if (t) |
| 270 | list[hdr_idx++] = qpack_sht[index]; |
| 271 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 272 | qpack_debug_printf(stderr, " t=%d index=%llu", !!t, (unsigned long long)index); |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 273 | } |
| 274 | else if (efl_type & QPACK_LFL_WNR_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 275 | /* Literal field line with name reference */ |
| 276 | uint64_t index, length; |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 277 | unsigned int t, n __maybe_unused, h; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 278 | |
| 279 | qpack_debug_printf(stderr, "Literal field line with name reference:"); |
| 280 | n = efl_type & 0x20; |
| 281 | t = efl_type & 0x10; |
| 282 | index = qpack_get_varint(&raw, &len, 4); |
| 283 | if (len == (uint64_t)-1) { |
| 284 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 285 | ret = -QPACK_ERR_TRUNCATED; |
| 286 | goto out; |
| 287 | } |
| 288 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 289 | if (t) |
| 290 | list[hdr_idx] = qpack_sht[index]; |
| 291 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 292 | qpack_debug_printf(stderr, " n=%d t=%d index=%llu", !!n, !!t, (unsigned long long)index); |
| 293 | h = *raw & 0x80; |
| 294 | length = qpack_get_varint(&raw, &len, 7); |
| 295 | if (len == (uint64_t)-1) { |
| 296 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 297 | ret = -QPACK_ERR_TRUNCATED; |
| 298 | goto out; |
| 299 | } |
| 300 | |
| 301 | qpack_debug_printf(stderr, " h=%d length=%llu", !!h, (unsigned long long)length); |
| 302 | if (h) { |
| 303 | char *trash; |
| 304 | int nlen; |
| 305 | |
| 306 | trash = chunk_newstr(tmp); |
| 307 | if (!trash) { |
| 308 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 309 | ret = -QPACK_DECOMPRESSION_FAILED; |
| 310 | goto out; |
| 311 | } |
| 312 | nlen = huff_dec(raw, length, trash, tmp->size - tmp->data); |
| 313 | if (nlen == (uint32_t)-1) { |
| 314 | qpack_debug_printf(stderr, " can't decode huffman.\n"); |
| 315 | ret = -QPACK_ERR_HUFFMAN; |
| 316 | goto out; |
| 317 | } |
| 318 | |
| 319 | qpack_debug_printf(stderr, " [name huff %d->%d '%s']", (int)length, (int)nlen, trash); |
Amaury Denoyelle | 9c8c4fa | 2021-09-30 17:14:55 +0200 | [diff] [blame] | 320 | /* makes an ist from tmp storage */ |
| 321 | b_add(tmp, nlen); |
| 322 | list[hdr_idx].v = ist2(trash, nlen); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 323 | } |
Amaury Denoyelle | 7d3aea5 | 2021-11-24 16:04:03 +0100 | [diff] [blame] | 324 | else { |
| 325 | list[hdr_idx].v = ist2(raw, length); |
| 326 | } |
| 327 | |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 328 | if (len < length) { |
| 329 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 330 | ret = -QPACK_ERR_TRUNCATED; |
| 331 | goto out; |
| 332 | } |
| 333 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 334 | raw += length; |
| 335 | len -= length; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 336 | ++hdr_idx; |
| 337 | } |
| 338 | else if (efl_type & QPACK_LFL_WLN_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 339 | /* Literal field line with literal name */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 340 | unsigned int n __maybe_unused, hname __maybe_unused, hvalue __maybe_unused; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 341 | uint64_t name_len, value_len; |
| 342 | |
| 343 | qpack_debug_printf(stderr, "Literal field line with literal name:"); |
| 344 | n = *raw & 0x10; |
| 345 | hname = *raw & 0x08; |
| 346 | name_len = qpack_get_varint(&raw, &len, 3); |
| 347 | if (len == (uint64_t)-1) { |
| 348 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 349 | ret = -QPACK_ERR_TRUNCATED; |
| 350 | goto out; |
| 351 | } |
| 352 | |
Amaury Denoyelle | ab9cec7 | 2022-02-14 14:45:10 +0100 | [diff] [blame] | 353 | qpack_debug_printf(stderr, " n=%d hname=%d name_len=%llu", !!n, !!hname, (unsigned long long)name_len); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 354 | /* Name string */ |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 355 | |
| 356 | if (len < name_len) { |
| 357 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 358 | ret = -QPACK_ERR_TRUNCATED; |
| 359 | goto out; |
| 360 | } |
| 361 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 362 | raw += name_len; |
| 363 | len -= name_len; |
| 364 | hvalue = *raw & 0x80; |
| 365 | value_len = qpack_get_varint(&raw, &len, 7); |
| 366 | if (len == (uint64_t)-1) { |
| 367 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 368 | ret = -QPACK_ERR_TRUNCATED; |
| 369 | goto out; |
| 370 | } |
| 371 | |
| 372 | qpack_debug_printf(stderr, " hvalue=%d value_len=%llu", !!hvalue, (unsigned long long)value_len); |
| 373 | |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 374 | if (len < value_len) { |
| 375 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 376 | ret = -QPACK_ERR_TRUNCATED; |
| 377 | goto out; |
| 378 | } |
| 379 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 380 | /* XXX Value string XXX */ |
| 381 | raw += value_len; |
| 382 | len -= value_len; |
| 383 | } |
| 384 | qpack_debug_printf(stderr, "\n"); |
| 385 | } |
| 386 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 387 | /* put an end marker */ |
| 388 | list[hdr_idx].n = list[hdr_idx].v = IST_NULL; |
| 389 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 390 | out: |
| 391 | qpack_debug_printf(stderr, "-- done: ret=%d\n", ret); |
| 392 | return ret; |
| 393 | } |