| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7f49816 commit b82f63d
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB) | |||
| 62 | 62 | set_target_properties(nghttp2_static PROPERTIES | |
| 63 | 63 | COMPILE_FLAGS "${WARNCFLAGS}" | |
| 64 | 64 | VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} | |
| 65 | - ARCHIVE_OUTPUT_NAME nghttp2 | ||
| 65 | + ARCHIVE_OUTPUT_NAME nghttp2_static | ||
| 66 | 66 | ) | |
| 67 | 67 | target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB") | |
| 68 | 68 | if(ENABLE_STATIC_LIB) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4769,6 +4769,19 @@ NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len); | |||
| 4769 | 4769 | */ | |
| 4770 | 4770 | NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len); | |
| 4771 | 4771 | ||
| 4772 | + /** | ||
| 4773 | + * @function | ||
| 4774 | + * | ||
| 4775 | + * Returns nonzero if the |value| which is supposed to the value of | ||
| 4776 | + * :authority or host header field is valid according to | ||
| 4777 | + * https://tools.ietf.org/html/rfc3986#section-3.2 | ||
| 4778 | + * | ||
| 4779 | + * |value| is valid if it merely consists of the allowed characters. | ||
| 4780 | + * In particular, it does not check whether |value| follows the syntax | ||
| 4781 | + * of authority. | ||
| 4782 | + */ | ||
| 4783 | + NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len); | ||
| 4784 | + | ||
| 4772 | 4785 | /* HPACK API */ | |
| 4773 | 4786 | ||
| 4774 | 4787 | struct nghttp2_hd_deflater; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,14 +29,14 @@ | |||
| 29 | 29 | * @macro | |
| 30 | 30 | * Version number of the nghttp2 library release | |
| 31 | 31 | */ | |
| 32 | - #define NGHTTP2_VERSION "1.39.2" | ||
| 32 | + #define NGHTTP2_VERSION "1.40.0" | ||
| 33 | 33 | ||
| 34 | 34 | /** | |
| 35 | 35 | * @macro | |
| 36 | 36 | * Numerical representation of the version number of the nghttp2 library | |
| 37 | 37 | * release. This is a 24 bit number with 8 bits for major number, 8 bits | |
| 38 | 38 | * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203. | |
| 39 | 39 | */ | |
| 40 | - #define NGHTTP2_VERSION_NUM 0x012702 | ||
| 40 | + #define NGHTTP2_VERSION_NUM 0x012800 | ||
| 41 | 41 | ||
| 42 | 42 | #endif /* NGHTTP2VER_H */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1694,6 +1694,11 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater, | |||
| 1694 | 1694 | DEBUGF("inflatehd: huffman decoding failed\n"); | |
| 1695 | 1695 | return readlen; | |
| 1696 | 1696 | } | |
| 1697 | + if (nghttp2_hd_huff_decode_failure_state(&inflater->huff_decode_ctx)) { | ||
| 1698 | + DEBUGF("inflatehd: huffman decoding failed\n"); | ||
| 1699 | + return NGHTTP2_ERR_HEADER_COMP; | ||
| 1700 | + } | ||
| 1701 | + | ||
| 1697 | 1702 | inflater->left -= (size_t)readlen; | |
| 1698 | 1703 | return readlen; | |
| 1699 | 1704 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -430,4 +430,10 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, | |||
| 430 | 430 | nghttp2_buf *buf, const uint8_t *src, | |
| 431 | 431 | size_t srclen, int fin); | |
| 432 | 432 | ||
| 433 | + /* | ||
| 434 | + * nghttp2_hd_huff_decode_failure_state returns nonzero if |ctx| | ||
| 435 | + * indicates that huffman decoding context is in failure state. | ||
| 436 | + */ | ||
| 437 | + int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx); | ||
| 438 | + | ||
| 433 | 439 | #endif /* NGHTTP2_HD_H */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,114 +29,7 @@ | |||
| 29 | 29 | #include <stdio.h> | |
| 30 | 30 | ||
| 31 | 31 | #include "nghttp2_hd.h" | |
| 32 | - | ||
| 33 | - /* | ||
| 34 | - * Encodes huffman code |sym| into |*dest_ptr|, whose least |rembits| | ||
| 35 | - * bits are not filled yet. The |rembits| must be in range [1, 8], | ||
| 36 | - * inclusive. At the end of the process, the |*dest_ptr| is updated | ||
| 37 | - * and points where next output should be placed. The number of | ||
| 38 | - * unfilled bits in the pointed location is returned. | ||
| 39 | - */ | ||
| 40 | - static ssize_t huff_encode_sym(nghttp2_bufs *bufs, size_t *avail_ptr, | ||
| 41 | - size_t rembits, const nghttp2_huff_sym *sym) { | ||
| 42 | - int rv; | ||
| 43 | - size_t nbits = sym->nbits; | ||
| 44 | - uint32_t code = sym->code; | ||
| 45 | - | ||
| 46 | - /* We assume that sym->nbits <= 32 */ | ||
| 47 | - if (rembits > nbits) { | ||
| 48 | - nghttp2_bufs_fast_orb_hold(bufs, (uint8_t)(code << (rembits - nbits))); | ||
| 49 | - return (ssize_t)(rembits - nbits); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - if (rembits == nbits) { | ||
| 53 | - nghttp2_bufs_fast_orb(bufs, (uint8_t)code); | ||
| 54 | - --*avail_ptr; | ||
| 55 | - return 8; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - nghttp2_bufs_fast_orb(bufs, (uint8_t)(code >> (nbits - rembits))); | ||
| 59 | - --*avail_ptr; | ||
| 60 | - | ||
| 61 | - nbits -= rembits; | ||
| 62 | - if (nbits & 0x7) { | ||
| 63 | - /* align code to MSB byte boundary */ | ||
| 64 | - code <<= 8 - (nbits & 0x7); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - if (*avail_ptr < (nbits + 7) / 8) { | ||
| 68 | - /* slow path */ | ||
| 69 | - if (nbits > 24) { | ||
| 70 | - rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 24)); | ||
| 71 | - if (rv != 0) { | ||
| 72 | - return rv; | ||
| 73 | - } | ||
| 74 | - nbits -= 8; | ||
| 75 | - } | ||
| 76 | - if (nbits > 16) { | ||
| 77 | - rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 16)); | ||
| 78 | - if (rv != 0) { | ||
| 79 | - return rv; | ||
| 80 | - } | ||
| 81 | - nbits -= 8; | ||
| 82 | - } | ||
| 83 | - if (nbits > 8) { | ||
| 84 | - rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 8)); | ||
| 85 | - if (rv != 0) { | ||
| 86 | - return rv; | ||
| 87 | - } | ||
| 88 | - nbits -= 8; | ||
| 89 | - } | ||
| 90 | - if (nbits == 8) { | ||
| 91 | - rv = nghttp2_bufs_addb(bufs, (uint8_t)code); | ||
| 92 | - if (rv != 0) { | ||
| 93 | - return rv; | ||
| 94 | - } | ||
| 95 | - *avail_ptr = nghttp2_bufs_cur_avail(bufs); | ||
| 96 | - return 8; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - rv = nghttp2_bufs_addb_hold(bufs, (uint8_t)code); | ||
| 100 | - if (rv != 0) { | ||
| 101 | - return rv; | ||
| 102 | - } | ||
| 103 | - *avail_ptr = nghttp2_bufs_cur_avail(bufs); | ||
| 104 | - return (ssize_t)(8 - nbits); | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - /* fast path, since most code is less than 8 */ | ||
| 108 | - if (nbits < 8) { | ||
| 109 | - nghttp2_bufs_fast_addb_hold(bufs, (uint8_t)code); | ||
| 110 | - *avail_ptr = nghttp2_bufs_cur_avail(bufs); | ||
| 111 | - return (ssize_t)(8 - nbits); | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - /* handle longer code path */ | ||
| 115 | - if (nbits > 24) { | ||
| 116 | - nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 24)); | ||
| 117 | - nbits -= 8; | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - if (nbits > 16) { | ||
| 121 | - nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 16)); | ||
| 122 | - nbits -= 8; | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - if (nbits > 8) { | ||
| 126 | - nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 8)); | ||
| 127 | - nbits -= 8; | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - if (nbits == 8) { | ||
| 131 | - nghttp2_bufs_fast_addb(bufs, (uint8_t)code); | ||
| 132 | - *avail_ptr = nghttp2_bufs_cur_avail(bufs); | ||
| 133 | - return 8; | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - nghttp2_bufs_fast_addb_hold(bufs, (uint8_t)code); | ||
| 137 | - *avail_ptr = nghttp2_bufs_cur_avail(bufs); | ||
| 138 | - return (ssize_t)(8 - nbits); | ||
| 139 | - } | ||
| 32 | + #include "nghttp2_net.h" | ||
| 140 | 33 | ||
| 141 | 34 | size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) { | |
| 142 | 35 | size_t i; | |
@@ -151,81 +44,101 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) { | |||
| 151 | 44 | ||
| 152 | 45 | int nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src, | |
| 153 | 46 | size_t srclen) { | |
| 154 | - int rv; | ||
| 155 | - ssize_t rembits = 8; | ||
| 156 | - size_t i; | ||
| 47 | + const nghttp2_huff_sym *sym; | ||
| 48 | + const uint8_t *end = src + srclen; | ||
| 49 | + uint64_t code = 0; | ||
| 50 | + uint32_t x; | ||
| 51 | + size_t nbits = 0; | ||
| 157 | 52 | size_t avail; | |
| 53 | + int rv; | ||
| 158 | 54 | ||
| 159 | 55 | avail = nghttp2_bufs_cur_avail(bufs); | |
| 160 | 56 | ||
| 161 | - for (i = 0; i < srclen; ++i) { | ||
| 162 | - const nghttp2_huff_sym *sym = &huff_sym_table[src[i]]; | ||
| 163 | - if (rembits == 8) { | ||
| 164 | - if (avail) { | ||
| 165 | - nghttp2_bufs_fast_addb_hold(bufs, 0); | ||
| 166 | - } else { | ||
| 167 | - rv = nghttp2_bufs_addb_hold(bufs, 0); | ||
| 168 | - if (rv != 0) { | ||
| 169 | - return rv; | ||
| 170 | - } | ||
| 171 | - avail = nghttp2_bufs_cur_avail(bufs); | ||
| 57 | + for (; src != end;) { | ||
| 58 | + sym = &huff_sym_table[*src++]; | ||
| 59 | + code |= (uint64_t)sym->code << (32 - nbits); | ||
| 60 | + nbits += sym->nbits; | ||
| 61 | + if (nbits < 32) { | ||
| 62 | + continue; | ||
| 63 | + } | ||
| 64 | + if (avail >= 4) { | ||
| 65 | + x = htonl((uint32_t)(code >> 32)); | ||
| 66 | + memcpy(bufs->cur->buf.last, &x, 4); | ||
| 67 | + bufs->cur->buf.last += 4; | ||
| 68 | + avail -= 4; | ||
| 69 | + code <<= 32; | ||
| 70 | + nbits -= 32; | ||
| 71 | + continue; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + for (; nbits >= 8;) { | ||
| 75 | + rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 56)); | ||
| 76 | + if (rv != 0) { | ||
| 77 | + return rv; | ||
| 172 | 78 | } | |
| 79 | + code <<= 8; | ||
| 80 | + nbits -= 8; | ||
| 173 | 81 | } | |
| 174 | - rembits = huff_encode_sym(bufs, &avail, (size_t)rembits, sym); | ||
| 175 | - if (rembits < 0) { | ||
| 176 | - return (int)rembits; | ||
| 82 | + | ||
| 83 | + avail = nghttp2_bufs_cur_avail(bufs); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + for (; nbits >= 8;) { | ||
| 87 | + rv = nghttp2_bufs_addb(bufs, (uint8_t)(code >> 56)); | ||
| 88 | + if (rv != 0) { | ||
| 89 | + return rv; | ||
| 177 | 90 | } | |
| 91 | + code <<= 8; | ||
| 92 | + nbits -= 8; | ||
| 178 | 93 | } | |
| 179 | - /* 256 is special terminal symbol, pad with its prefix */ | ||
| 180 | - if (rembits < 8) { | ||
| 181 | - /* if rembits < 8, we should have at least 1 buffer space | ||
| 182 | - available */ | ||
| 183 | - const nghttp2_huff_sym *sym = &huff_sym_table[256]; | ||
| 184 | - assert(avail); | ||
| 185 | - /* Caution we no longer adjust avail here */ | ||
| 186 | - nghttp2_bufs_fast_orb( | ||
| 187 | - bufs, (uint8_t)(sym->code >> (sym->nbits - (size_t)rembits))); | ||
| 94 | + | ||
| 95 | + if (nbits) { | ||
| 96 | + rv = nghttp2_bufs_addb( | ||
| 97 | + bufs, (uint8_t)((uint8_t)(code >> 56) | ((1 << (8 - nbits)) - 1))); | ||
| 98 | + if (rv != 0) { | ||
| 99 | + return rv; | ||
| 100 | + } | ||
| 188 | 101 | } | |
| 189 | 102 | ||
| 190 | 103 | return 0; | |
| 191 | 104 | } | |
| 192 | 105 | ||
| 193 | 106 | void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx) { | |
| 194 | - ctx->state = 0; | ||
| 195 | - ctx->accept = 1; | ||
| 107 | + ctx->fstate = NGHTTP2_HUFF_ACCEPTED; | ||
| 196 | 108 | } | |
| 197 | 109 | ||
| 198 | 110 | ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, | |
| 199 | 111 | nghttp2_buf *buf, const uint8_t *src, | |
| 200 | 112 | size_t srclen, int final) { | |
| 201 | - size_t i; | ||
| 113 | + const uint8_t *end = src + srclen; | ||
| 114 | + nghttp2_huff_decode node = {ctx->fstate, 0}; | ||
| 115 | + const nghttp2_huff_decode *t = &node; | ||
| 116 | + uint8_t c; | ||
| 202 | 117 | ||
| 203 | 118 | /* We use the decoding algorithm described in | |
| 204 | 119 | http://graphics.ics.uci.edu/pub/Prefix.pdf */ | |
| 205 | - for (i = 0; i < srclen; ++i) { | ||
| 206 | - const nghttp2_huff_decode *t; | ||
| 207 | - | ||
| 208 | - t = &huff_decode_table[ctx->state][src[i] >> 4]; | ||
| 209 | - if (t->flags & NGHTTP2_HUFF_FAIL) { | ||
| 210 | - return NGHTTP2_ERR_HEADER_COMP; | ||
| 211 | - } | ||
| 212 | - if (t->flags & NGHTTP2_HUFF_SYM) { | ||
| 120 | + for (; src != end;) { | ||
| 121 | + c = *src++; | ||
| 122 | + t = &huff_decode_table[t->fstate & 0x1ff][c >> 4]; | ||
| 123 | + if (t->fstate & NGHTTP2_HUFF_SYM) { | ||
| 213 | 124 | *buf->last++ = t->sym; | |
| 214 | 125 | } | |
| 215 | 126 | ||
| 216 | - t = &huff_decode_table[t->state][src[i] & 0xf]; | ||
| 217 | - if (t->flags & NGHTTP2_HUFF_FAIL) { | ||
| 218 | - return NGHTTP2_ERR_HEADER_COMP; | ||
| 219 | - } | ||
| 220 | - if (t->flags & NGHTTP2_HUFF_SYM) { | ||
| 127 | + t = &huff_decode_table[t->fstate & 0x1ff][c & 0xf]; | ||
| 128 | + if (t->fstate & NGHTTP2_HUFF_SYM) { | ||
| 221 | 129 | *buf->last++ = t->sym; | |
| 222 | 130 | } | |
| 223 | - | ||
| 224 | - ctx->state = t->state; | ||
| 225 | - ctx->accept = (t->flags & NGHTTP2_HUFF_ACCEPTED) != 0; | ||
| 226 | 131 | } | |
| 227 | - if (final && !ctx->accept) { | ||
| 132 | + | ||
| 133 | + ctx->fstate = t->fstate; | ||
| 134 | + | ||
| 135 | + if (final && !(ctx->fstate & NGHTTP2_HUFF_ACCEPTED)) { | ||
| 228 | 136 | return NGHTTP2_ERR_HEADER_COMP; | |
| 229 | 137 | } | |
| 230 | - return (ssize_t)i; | ||
| 138 | + | ||
| 139 | + return (ssize_t)srclen; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx) { | ||
| 143 | + return ctx->fstate == 0x100; | ||
| 231 | 144 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,34 +34,29 @@ | |||
| 34 | 34 | typedef enum { | |
| 35 | 35 | /* FSA accepts this state as the end of huffman encoding | |
| 36 | 36 | sequence. */ | |
| 37 | - NGHTTP2_HUFF_ACCEPTED = 1, | ||
| 37 | + NGHTTP2_HUFF_ACCEPTED = 1 << 14, | ||
| 38 | 38 | /* This state emits symbol */ | |
| 39 | - NGHTTP2_HUFF_SYM = (1 << 1), | ||
| 40 | - /* If state machine reaches this state, decoding fails. */ | ||
| 41 | - NGHTTP2_HUFF_FAIL = (1 << 2) | ||
| 39 | + NGHTTP2_HUFF_SYM = 1 << 15, | ||
| 42 | 40 | } nghttp2_huff_decode_flag; | |
| 43 | 41 | ||
| 44 | 42 | typedef struct { | |
| 45 | - /* huffman decoding state, which is actually the node ID of internal | ||
| 46 | - huffman tree. We have 257 leaf nodes, but they are identical to | ||
| 47 | - root node other than emitting a symbol, so we have 256 internal | ||
| 48 | - nodes [1..255], inclusive. */ | ||
| 49 | - uint8_t state; | ||
| 50 | - /* bitwise OR of zero or more of the nghttp2_huff_decode_flag */ | ||
| 51 | - uint8_t flags; | ||
| 43 | + /* fstate is the current huffman decoding state, which is actually | ||
| 44 | + the node ID of internal huffman tree with | ||
| 45 | + nghttp2_huff_decode_flag OR-ed. We have 257 leaf nodes, but they | ||
| 46 | + are identical to root node other than emitting a symbol, so we | ||
| 47 | + have 256 internal nodes [1..255], inclusive. The node ID 256 is | ||
| 48 | + a special node and it is a terminal state that means decoding | ||
| 49 | + failed. */ | ||
| 50 | + uint16_t fstate; | ||
| 52 | 51 | /* symbol if NGHTTP2_HUFF_SYM flag set */ | |
| 53 | 52 | uint8_t sym; | |
| 54 | 53 | } nghttp2_huff_decode; | |
| 55 | 54 | ||
| 56 | 55 | typedef nghttp2_huff_decode huff_decode_table_type[16]; | |
| 57 | 56 | ||
| 58 | 57 | typedef struct { | |
| 59 | - /* Current huffman decoding state. We stripped leaf nodes, so the | ||
| 60 | - value range is [0..255], inclusive. */ | ||
| 61 | - uint8_t state; | ||
| 62 | - /* nonzero if we can say that the decoding process succeeds at this | ||
| 63 | - state */ | ||
| 64 | - uint8_t accept; | ||
| 58 | + /* fstate is the current huffman decoding state. */ | ||
| 59 | + uint16_t fstate; | ||
| 65 | 60 | } nghttp2_hd_huff_decode_context; | |
| 66 | 61 | ||
| 67 | 62 | typedef struct { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments