Repository navigation
Bun.serve(http3): send a response whose header block is larger than 64 KB #42905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
4
commits into
main
Choose a base branch
from
robobun/dc5f7931/http3-large-header-block
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6702342
Bun.serve(http3): send a response whose header block is larger than 6…
robobun 16a15ea
Merge branch 'main' into robobun/dc5f7931/http3-large-header-block
robobun 92e86de
test: compare the large header values, cover the node:quic send path
robobun 438ac1a
ci: retrigger
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| --- a/src/liblsquic/lsquic_stream.c | ||
| +++ b/src/liblsquic/lsquic_stream.c | ||
| @@ -53,6 +53,7 @@ | ||
| #include "lsquic_ev_log.h" | ||
| #include "lsquic_enc_sess.h" | ||
| #include "lsqpack.h" | ||
| +#include "lsxpack_header.h" | ||
| #include "lsquic_frab_list.h" | ||
| #include "lsquic_http1x_if.h" | ||
| #include "lsquic_qdec_hdl.h" | ||
| @@ -4113,9 +4114,28 @@ stream_write_buf (struct lsquic_stream *stream, const void *buf, size_t sz) | ||
| } | ||
|
|
||
|
|
||
| -/* This limits the cumulative size of the compressed header fields */ | ||
| +/* Compressed header blocks up to this size are encoded on the stack. Larger | ||
| + * ones go through a heap buffer sized from the header list. | ||
| + */ | ||
| #define MAX_HEADERS_SIZE (64 * 1024) | ||
|
|
||
| +/* bun: upper bound on the size of the compressed header block. QPACK picks | ||
| + * Huffman only when it is shorter than the literal, so a field line is at | ||
| + * most its name and value plus one prefix byte and one integer for each. | ||
| + */ | ||
| +static size_t | ||
| +headers_max_encoded_size (const struct lsquic_http_headers *headers) | ||
| +{ | ||
| + size_t size = 0; | ||
| + int i; | ||
| + | ||
| + for (i = 0; i < headers->count; ++i) | ||
| + if (headers->headers[i].buf) | ||
| + size += 2 * LSQPACK_UINT64_ENC_SZ + headers->headers[i].name_len | ||
| + + headers->headers[i].val_len; | ||
| + return size; | ||
| +} | ||
| + | ||
| static int | ||
| send_headers_ietf (struct lsquic_stream *stream, | ||
| const struct lsquic_http_headers *headers, int eos) | ||
| @@ -4132,7 +4152,11 @@ send_headers_ietf (struct lsquic_stream *stream, | ||
| unsigned char *header_block; | ||
| enum lsqpack_enc_header_flags hflags; | ||
| int rv; | ||
| - const size_t buf_sz = max_push_size + max_prefix_size + MAX_HEADERS_SIZE; | ||
| + const size_t max_headers_size = headers_max_encoded_size(headers); | ||
| + const size_t buf_sz = max_push_size + max_prefix_size | ||
| + + (max_headers_size > MAX_HEADERS_SIZE ? max_headers_size | ||
| + : MAX_HEADERS_SIZE); | ||
| + unsigned char *buf; | ||
|
|
||
| if (stream->sm_send_headers_state != SSHS_BEGIN || stream->sm_header_block) | ||
| { | ||
| @@ -4141,9 +4165,20 @@ send_headers_ietf (struct lsquic_stream *stream, | ||
| return -1; | ||
| } | ||
| #ifndef WIN32 | ||
| - unsigned char buf[buf_sz]; | ||
| + unsigned char stack_buf[max_push_size + max_prefix_size + MAX_HEADERS_SIZE]; | ||
| + if (max_headers_size > MAX_HEADERS_SIZE) | ||
| + { | ||
| + buf = malloc(buf_sz); | ||
| + if (!buf) | ||
| + { | ||
| + LSQ_WARN("cannot allocate %zu bytes for header block", buf_sz); | ||
| + return -1; | ||
| + } | ||
| + } | ||
| + else | ||
| + buf = stack_buf; | ||
| #else | ||
| - unsigned char *buf = _malloca(buf_sz); | ||
| + buf = _malloca(buf_sz); | ||
| if (!buf) | ||
| return -1; | ||
| #endif | ||
| @@ -4234,6 +4269,9 @@ send_headers_ietf (struct lsquic_stream *stream, | ||
| clean: | ||
| #ifdef WIN32 | ||
| _freea(buf); | ||
| +#else | ||
| + if (buf != stack_buf) | ||
| + free(buf); | ||
| #endif | ||
| return rv; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.