Skip to content

Commit 2960ef1

Browse files
gengjiawentargos
authored andcommitted
deps: update nghttp2 to 1.40.0
PR-URL: #30493 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2ad7003 commit 2960ef1

11 files changed

Lines changed: 4387 additions & 4432 deletions

‎deps/nghttp2/lib/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
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_NAMEnghttp2
65+
ARCHIVE_OUTPUT_NAMEnghttp2_static
6666
)
6767
target_compile_definitions(nghttp2_staticPUBLIC"-DNGHTTP2_STATICLIB")
6868
if(ENABLE_STATIC_LIB)

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

Lines changed: 13 additions & 0 deletions
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_EXTERNintnghttp2_check_header_value(constuint8_t*value, size_tlen);
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_EXTERNintnghttp2_check_authority(constuint8_t*value, size_tlen);
4784+
47724785
/* HPACK API */
47734786

47744787
structnghttp2_hd_deflater;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* @macro
3030
* Version number of the nghttp2 library release
3131
*/
32-
#defineNGHTTP2_VERSION "1.39.2"
32+
#defineNGHTTP2_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-
#defineNGHTTP2_VERSION_NUM0x012702
40+
#defineNGHTTP2_VERSION_NUM0x012800
4141

4242
#endif/* NGHTTP2VER_H */

‎deps/nghttp2/lib/nghttp2_hd.c‎

Lines changed: 5 additions & 0 deletions
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
returnreadlen;
16961696
}
1697+
if (nghttp2_hd_huff_decode_failure_state(&inflater->huff_decode_ctx)) {
1698+
DEBUGF("inflatehd: huffman decoding failed\n");
1699+
returnNGHTTP2_ERR_HEADER_COMP;
1700+
}
1701+
16971702
inflater->left-= (size_t)readlen;
16981703
returnreadlen;
16991704
}

‎deps/nghttp2/lib/nghttp2_hd.h‎

Lines changed: 6 additions & 0 deletions
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, constuint8_t*src,
431431
size_tsrclen, intfin);
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+
intnghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context*ctx);
438+
433439
#endif/* NGHTTP2_HD_H */

‎deps/nghttp2/lib/nghttp2_hd_huffman.c‎

Lines changed: 68 additions & 155 deletions
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-
staticssize_thuff_encode_sym(nghttp2_bufs*bufs, size_t*avail_ptr,
41-
size_trembits, constnghttp2_huff_sym*sym) {
42-
intrv;
43-
size_tnbits=sym->nbits;
44-
uint32_tcode=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-
return8;
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-
returnrv;
73-
}
74-
nbits-=8;
75-
}
76-
if (nbits>16) {
77-
rv=nghttp2_bufs_addb(bufs, (uint8_t)(code >> 16));
78-
if (rv!=0) {
79-
returnrv;
80-
}
81-
nbits-=8;
82-
}
83-
if (nbits>8) {
84-
rv=nghttp2_bufs_addb(bufs, (uint8_t)(code >> 8));
85-
if (rv!=0) {
86-
returnrv;
87-
}
88-
nbits-=8;
89-
}
90-
if (nbits==8) {
91-
rv=nghttp2_bufs_addb(bufs, (uint8_t)code);
92-
if (rv!=0) {
93-
returnrv;
94-
}
95-
*avail_ptr=nghttp2_bufs_cur_avail(bufs);
96-
return8;
97-
}
98-
99-
rv=nghttp2_bufs_addb_hold(bufs, (uint8_t)code);
100-
if (rv!=0) {
101-
returnrv;
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-
return8;
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_tnghttp2_hd_huff_encode_count(constuint8_t*src, size_tlen) {
14235
size_ti;
@@ -151,81 +44,101 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) {
15144

15245
intnghttp2_hd_huff_encode(nghttp2_bufs*bufs, constuint8_t*src,
15346
size_tsrclen) {
154-
intrv;
155-
ssize_trembits=8;
156-
size_ti;
47+
constnghttp2_huff_sym*sym;
48+
constuint8_t*end=src+srclen;
49+
uint64_tcode=0;
50+
uint32_tx;
51+
size_tnbits=0;
15752
size_tavail;
53+
intrv;
15854

15955
avail=nghttp2_bufs_cur_avail(bufs);
16056

161-
for (i=0; i<srclen; ++i) {
162-
constnghttp2_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-
returnrv;
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+
returnrv;
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+
returnrv;
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-
constnghttp2_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+
returnrv;
100+
}
188101
}
189102

190103
return0;
191104
}
192105

193106
voidnghttp2_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_tnghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context*ctx,
199111
nghttp2_buf*buf, constuint8_t*src,
200112
size_tsrclen, intfinal) {
201-
size_ti;
113+
constuint8_t*end=src+srclen;
114+
nghttp2_huff_decodenode= {ctx->fstate, 0};
115+
constnghttp2_huff_decode*t=&node;
116+
uint8_tc;
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-
constnghttp2_huff_decode*t;
207-
208-
t=&huff_decode_table[ctx->state][src[i] >> 4];
209-
if (t->flags&NGHTTP2_HUFF_FAIL) {
210-
returnNGHTTP2_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-
returnNGHTTP2_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
returnNGHTTP2_ERR_HEADER_COMP;
229137
}
230-
return (ssize_t)i;
138+
139+
return (ssize_t)srclen;
140+
}
141+
142+
intnghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context*ctx) {
143+
returnctx->fstate==0x100;
231144
}

‎deps/nghttp2/lib/nghttp2_hd_huffman.h‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,29 @@
3434
typedefenum {
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
typedefstruct {
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_tstate;
50-
/* bitwise OR of zero or more of the nghttp2_huff_decode_flag */
51-
uint8_tflags;
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_tfstate;
5251
/* symbol if NGHTTP2_HUFF_SYM flag set */
5352
uint8_tsym;
5453
} nghttp2_huff_decode;
5554

5655
typedefnghttp2_huff_decodehuff_decode_table_type[16];
5756

5857
typedefstruct {
59-
/* Current huffman decoding state. We stripped leaf nodes, so the
60-
value range is [0..255], inclusive. */
61-
uint8_tstate;
62-
/* nonzero if we can say that the decoding process succeeds at this
63-
state */
64-
uint8_taccept;
58+
/* fstate is the current huffman decoding state. */
59+
uint16_tfstate;
6560
} nghttp2_hd_huff_decode_context;
6661

6762
typedefstruct {

0 commit comments

Comments
 (0)