Skip to content

Commit b82f63d

Browse files
gengjiawenBridgeAR
authored andcommitted
deps: update nghttp2 to 1.40.0
PR-URL: #30493 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 7f49816 commit b82f63d

11 files changed

+4387
-4432
lines changed

deps/nghttp2/lib/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB)
6262
set_target_properties(nghttp2_static PROPERTIES
6363
COMPILE_FLAGS "${WARNCFLAGS}"
6464
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
65-
ARCHIVE_OUTPUT_NAME nghttp2
65+
ARCHIVE_OUTPUT_NAME nghttp2_static
6666
)
6767
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
6868
if(ENABLE_STATIC_LIB)

deps/nghttp2/lib/includes/nghttp2/nghttp2.h

+13
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,19 @@ NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
47694769
*/
47704770
NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
47714771

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+
47724785
/* HPACK API */
47734786

47744787
struct nghttp2_hd_deflater;

deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* @macro
3030
* Version number of the nghttp2 library release
3131
*/
32-
#define NGHTTP2_VERSION "1.39.2"
32+
#define NGHTTP2_VERSION "1.40.0"
3333

3434
/**
3535
* @macro
3636
* Numerical representation of the version number of the nghttp2 library
3737
* release. This is a 24 bit number with 8 bits for major number, 8 bits
3838
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
3939
*/
40-
#define NGHTTP2_VERSION_NUM 0x012702
40+
#define NGHTTP2_VERSION_NUM 0x012800
4141

4242
#endif /* NGHTTP2VER_H */

deps/nghttp2/lib/nghttp2_hd.c

+5
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,11 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater,
16941694
DEBUGF("inflatehd: huffman decoding failed\n");
16951695
return readlen;
16961696
}
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+
16971702
inflater->left -= (size_t)readlen;
16981703
return readlen;
16991704
}

deps/nghttp2/lib/nghttp2_hd.h

+6
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,10 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
430430
nghttp2_buf *buf, const uint8_t *src,
431431
size_t srclen, int fin);
432432

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+
433439
#endif /* NGHTTP2_HD_H */

deps/nghttp2/lib/nghttp2_hd_huffman.c

+68-155
Original file line numberDiff line numberDiff line change
@@ -29,114 +29,7 @@
2929
#include <stdio.h>
3030

3131
#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"
14033

14134
size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) {
14235
size_t i;
@@ -151,81 +44,101 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) {
15144

15245
int nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src,
15346
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;
15752
size_t avail;
53+
int rv;
15854

15955
avail = nghttp2_bufs_cur_avail(bufs);
16056

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;
17278
}
79+
code <<= 8;
80+
nbits -= 8;
17381
}
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;
17790
}
91+
code <<= 8;
92+
nbits -= 8;
17893
}
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+
}
188101
}
189102

190103
return 0;
191104
}
192105

193106
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;
196108
}
197109

198110
ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
199111
nghttp2_buf *buf, const uint8_t *src,
200112
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;
202117

203118
/* We use the decoding algorithm described in
204119
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) {
213124
*buf->last++ = t->sym;
214125
}
215126

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) {
221129
*buf->last++ = t->sym;
222130
}
223-
224-
ctx->state = t->state;
225-
ctx->accept = (t->flags & NGHTTP2_HUFF_ACCEPTED) != 0;
226131
}
227-
if (final && !ctx->accept) {
132+
133+
ctx->fstate = t->fstate;
134+
135+
if (final && !(ctx->fstate & NGHTTP2_HUFF_ACCEPTED)) {
228136
return NGHTTP2_ERR_HEADER_COMP;
229137
}
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;
231144
}

deps/nghttp2/lib/nghttp2_hd_huffman.h

+12-17
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,29 @@
3434
typedef enum {
3535
/* FSA accepts this state as the end of huffman encoding
3636
sequence. */
37-
NGHTTP2_HUFF_ACCEPTED = 1,
37+
NGHTTP2_HUFF_ACCEPTED = 1 << 14,
3838
/* 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,
4240
} nghttp2_huff_decode_flag;
4341

4442
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;
5251
/* symbol if NGHTTP2_HUFF_SYM flag set */
5352
uint8_t sym;
5453
} nghttp2_huff_decode;
5554

5655
typedef nghttp2_huff_decode huff_decode_table_type[16];
5756

5857
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;
6560
} nghttp2_hd_huff_decode_context;
6661

6762
typedef struct {

0 commit comments

Comments
 (0)