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> |
| 30 | #include <haproxy/qpack-t.h> |
| 31 | #include <haproxy/qpack-dec.h> |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 32 | #include <haproxy/qpack-tbl.h> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 33 | #include <haproxy/hpack-huff.h> |
| 34 | #include <haproxy/hpack-tbl.h> |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 35 | #include <haproxy/http-hdr.h> |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 36 | #include <haproxy/tools.h> |
| 37 | |
Amaury Denoyelle | d96361b | 2022-03-25 14:56:51 +0100 | [diff] [blame] | 38 | #if defined(DEBUG_QPACK) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 39 | #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 | */ |
| 60 | static 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écaille | 6842485 | 2022-02-02 14:56:23 +0100 | [diff] [blame] | 68 | ret = *raw++ & ((1ULL << b) - 1); |
| 69 | if (ret != (uint64_t)((1ULL << b) - 1)) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 70 | 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 Denoyelle | 5869cb6 | 2022-05-31 15:21:27 +0200 | [diff] [blame] | 95 | /* Decode an encoder stream. |
| 96 | * |
| 97 | * Returns 0 on success else non-zero. |
| 98 | */ |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 99 | int qpack_decode_enc(struct buffer *buf, void *ctx) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 100 | { |
| 101 | size_t len; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 102 | unsigned char inst; |
| 103 | |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 104 | len = b_data(buf); |
| 105 | qpack_debug_hexdump(stderr, "[QPACK-DEC-ENC] ", b_head(buf), 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 | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 112 | inst = (unsigned char)*b_head(buf) & 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 | |
Amaury Denoyelle | 5869cb6 | 2022-05-31 15:21:27 +0200 | [diff] [blame] | 126 | return 0; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Amaury Denoyelle | 5869cb6 | 2022-05-31 15:21:27 +0200 | [diff] [blame] | 129 | /* Decode an decoder stream. |
| 130 | * |
| 131 | * Returns 0 on success else non-zero. |
| 132 | */ |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 133 | int qpack_decode_dec(struct buffer *buf, void *ctx) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 134 | { |
| 135 | size_t len; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 136 | unsigned char inst; |
| 137 | |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 138 | len = b_data(buf); |
| 139 | qpack_debug_hexdump(stderr, "[QPACK-DEC-DEC] ", b_head(buf), 0, len); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 140 | |
| 141 | if (!len) { |
| 142 | qpack_debug_printf(stderr, "[QPACK-DEC-DEC] empty stream\n"); |
| 143 | return 0; |
| 144 | } |
| 145 | |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame^] | 146 | inst = (unsigned char)*b_head(buf) & QPACK_DEC_INST_BITMASK; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 147 | 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 Denoyelle | 5869cb6 | 2022-05-31 15:21:27 +0200 | [diff] [blame] | 157 | return 0; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 158 | } |
| 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 | */ |
| 164 | static 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 Denoyelle | c5d31ed | 2022-06-14 17:34:53 +0200 | [diff] [blame] | 179 | /* Decode a field section from the <raw> buffer of <len> bytes. Each parsed |
| 180 | * header is inserted into <list> and uses <tmp> as a storage for some elements |
| 181 | * pointing into it. An end marker is inserted at the end of the list with |
| 182 | * empty strings as name/value. |
| 183 | * |
| 184 | * Returns 0 on success. In case of error, a negative code QPACK_ERR_* is |
| 185 | * returned. |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 186 | */ |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 187 | int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp, |
| 188 | struct http_hdr *list) |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 189 | { |
| 190 | uint64_t enc_ric, db; |
| 191 | int s; |
| 192 | unsigned int efl_type; |
| 193 | int ret; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 194 | int hdr_idx = 0; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 195 | |
| 196 | qpack_debug_hexdump(stderr, "[QPACK-DEC-FS] ", (const char *)raw, 0, len); |
| 197 | |
Amaury Denoyelle | c5d31ed | 2022-06-14 17:34:53 +0200 | [diff] [blame] | 198 | /* parse field section prefix */ |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 199 | ret = qpack_decode_fs_pfx(&enc_ric, &db, &s, &raw, &len); |
| 200 | if (ret < 0) { |
| 201 | qpack_debug_printf(stderr, "##ERR@%d(%d)\n", __LINE__, ret); |
| 202 | goto out; |
| 203 | } |
| 204 | |
| 205 | chunk_reset(tmp); |
| 206 | qpack_debug_printf(stderr, "enc_ric: %llu db: %llu s=%d\n", |
| 207 | (unsigned long long)enc_ric, (unsigned long long)db, !!s); |
| 208 | /* Decode field lines */ |
| 209 | while (len) { |
Amaury Denoyelle | c5d31ed | 2022-06-14 17:34:53 +0200 | [diff] [blame] | 210 | /* parse field line representation */ |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 211 | efl_type = *raw & QPACK_EFL_BITMASK; |
| 212 | qpack_debug_printf(stderr, "efl_type=0x%02x\n", efl_type); |
Amaury Denoyelle | c5d31ed | 2022-06-14 17:34:53 +0200 | [diff] [blame] | 213 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 214 | if (efl_type == QPACK_LFL_WPBNM) { |
| 215 | /* Literal field line with post-base name reference */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 216 | uint64_t index __maybe_unused, length; |
Amaury Denoyelle | d96361b | 2022-03-25 14:56:51 +0100 | [diff] [blame] | 217 | unsigned int n __maybe_unused, h __maybe_unused; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 218 | |
| 219 | qpack_debug_printf(stderr, "literal field line with post-base name reference:"); |
| 220 | n = *raw & 0x08; |
| 221 | index = qpack_get_varint(&raw, &len, 3); |
| 222 | if (len == (uint64_t)-1) { |
| 223 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 224 | ret = -QPACK_ERR_TRUNCATED; |
| 225 | goto out; |
| 226 | } |
| 227 | |
| 228 | qpack_debug_printf(stderr, " n=%d index=%llu", !!n, (unsigned long long)index); |
| 229 | h = *raw & 0x80; |
| 230 | length = qpack_get_varint(&raw, &len, 7); |
| 231 | if (len == (uint64_t)-1) { |
| 232 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 233 | ret = -QPACK_ERR_TRUNCATED; |
| 234 | goto out; |
| 235 | } |
| 236 | |
| 237 | 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] | 238 | |
| 239 | if (len < length) { |
| 240 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 241 | ret = -QPACK_ERR_TRUNCATED; |
| 242 | goto out; |
| 243 | } |
| 244 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 245 | /* XXX Value string XXX */ |
| 246 | raw += length; |
| 247 | len -= length; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 248 | } |
| 249 | else if (efl_type == QPACK_IFL_WPBI) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 250 | /* Indexed field line with post-base index */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 251 | uint64_t index __maybe_unused; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 252 | |
| 253 | qpack_debug_printf(stderr, "indexed field line with post-base index:"); |
| 254 | index = qpack_get_varint(&raw, &len, 4); |
| 255 | if (len == (uint64_t)-1) { |
| 256 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 257 | ret = -QPACK_ERR_TRUNCATED; |
| 258 | goto out; |
| 259 | } |
| 260 | |
| 261 | qpack_debug_printf(stderr, " index=%llu", (unsigned long long)index); |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 262 | } |
| 263 | else if (efl_type & QPACK_IFL_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 264 | /* Indexed field line */ |
| 265 | uint64_t index; |
| 266 | unsigned int t; |
| 267 | |
| 268 | qpack_debug_printf(stderr, "indexed field line:"); |
| 269 | t = efl_type & 0x40; |
| 270 | index = qpack_get_varint(&raw, &len, 6); |
| 271 | if (len == (uint64_t)-1) { |
| 272 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 273 | ret = -QPACK_ERR_TRUNCATED; |
| 274 | goto out; |
| 275 | } |
| 276 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 277 | if (t) |
| 278 | list[hdr_idx++] = qpack_sht[index]; |
| 279 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 280 | 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] | 281 | } |
| 282 | else if (efl_type & QPACK_LFL_WNR_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 283 | /* Literal field line with name reference */ |
| 284 | uint64_t index, length; |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 285 | unsigned int t, n __maybe_unused, h; |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 286 | |
| 287 | qpack_debug_printf(stderr, "Literal field line with name reference:"); |
| 288 | n = efl_type & 0x20; |
| 289 | t = efl_type & 0x10; |
| 290 | index = qpack_get_varint(&raw, &len, 4); |
| 291 | if (len == (uint64_t)-1) { |
| 292 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 293 | ret = -QPACK_ERR_TRUNCATED; |
| 294 | goto out; |
| 295 | } |
| 296 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 297 | if (t) |
| 298 | list[hdr_idx] = qpack_sht[index]; |
| 299 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 300 | qpack_debug_printf(stderr, " n=%d t=%d index=%llu", !!n, !!t, (unsigned long long)index); |
| 301 | h = *raw & 0x80; |
| 302 | length = qpack_get_varint(&raw, &len, 7); |
| 303 | if (len == (uint64_t)-1) { |
| 304 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 305 | ret = -QPACK_ERR_TRUNCATED; |
| 306 | goto out; |
| 307 | } |
| 308 | |
| 309 | qpack_debug_printf(stderr, " h=%d length=%llu", !!h, (unsigned long long)length); |
| 310 | if (h) { |
| 311 | char *trash; |
| 312 | int nlen; |
| 313 | |
| 314 | trash = chunk_newstr(tmp); |
| 315 | if (!trash) { |
| 316 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 317 | ret = -QPACK_DECOMPRESSION_FAILED; |
| 318 | goto out; |
| 319 | } |
| 320 | nlen = huff_dec(raw, length, trash, tmp->size - tmp->data); |
| 321 | if (nlen == (uint32_t)-1) { |
| 322 | qpack_debug_printf(stderr, " can't decode huffman.\n"); |
| 323 | ret = -QPACK_ERR_HUFFMAN; |
| 324 | goto out; |
| 325 | } |
| 326 | |
| 327 | 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] | 328 | /* makes an ist from tmp storage */ |
| 329 | b_add(tmp, nlen); |
| 330 | list[hdr_idx].v = ist2(trash, nlen); |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 331 | } |
Amaury Denoyelle | 7d3aea5 | 2021-11-24 16:04:03 +0100 | [diff] [blame] | 332 | else { |
| 333 | list[hdr_idx].v = ist2(raw, length); |
| 334 | } |
| 335 | |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 336 | if (len < length) { |
| 337 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 338 | ret = -QPACK_ERR_TRUNCATED; |
| 339 | goto out; |
| 340 | } |
| 341 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 342 | raw += length; |
| 343 | len -= length; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 344 | ++hdr_idx; |
| 345 | } |
| 346 | else if (efl_type & QPACK_LFL_WLN_BIT) { |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 347 | /* Literal field line with literal name */ |
Amaury Denoyelle | 18a10d0 | 2022-03-25 15:11:38 +0100 | [diff] [blame] | 348 | 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] | 349 | uint64_t name_len, value_len; |
| 350 | |
| 351 | qpack_debug_printf(stderr, "Literal field line with literal name:"); |
| 352 | n = *raw & 0x10; |
| 353 | hname = *raw & 0x08; |
| 354 | name_len = qpack_get_varint(&raw, &len, 3); |
| 355 | if (len == (uint64_t)-1) { |
| 356 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 357 | ret = -QPACK_ERR_TRUNCATED; |
| 358 | goto out; |
| 359 | } |
| 360 | |
Amaury Denoyelle | ab9cec7 | 2022-02-14 14:45:10 +0100 | [diff] [blame] | 361 | 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] | 362 | /* Name string */ |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 363 | |
| 364 | if (len < name_len) { |
| 365 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 366 | ret = -QPACK_ERR_TRUNCATED; |
| 367 | goto out; |
| 368 | } |
| 369 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 370 | raw += name_len; |
| 371 | len -= name_len; |
| 372 | hvalue = *raw & 0x80; |
| 373 | value_len = qpack_get_varint(&raw, &len, 7); |
| 374 | if (len == (uint64_t)-1) { |
| 375 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 376 | ret = -QPACK_ERR_TRUNCATED; |
| 377 | goto out; |
| 378 | } |
| 379 | |
| 380 | qpack_debug_printf(stderr, " hvalue=%d value_len=%llu", !!hvalue, (unsigned long long)value_len); |
| 381 | |
Frédéric Lécaille | e629cfd | 2021-12-15 14:16:16 +0100 | [diff] [blame] | 382 | if (len < value_len) { |
| 383 | qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__); |
| 384 | ret = -QPACK_ERR_TRUNCATED; |
| 385 | goto out; |
| 386 | } |
| 387 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 388 | /* XXX Value string XXX */ |
| 389 | raw += value_len; |
| 390 | len -= value_len; |
| 391 | } |
| 392 | qpack_debug_printf(stderr, "\n"); |
| 393 | } |
| 394 | |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 395 | /* put an end marker */ |
| 396 | list[hdr_idx].n = list[hdr_idx].v = IST_NULL; |
| 397 | |
Frédéric Lécaille | b4672fb | 2021-03-03 16:13:10 +0100 | [diff] [blame] | 398 | out: |
| 399 | qpack_debug_printf(stderr, "-- done: ret=%d\n", ret); |
| 400 | return ret; |
| 401 | } |