Skip to content

Stop sending empty data frame when input stream ends but the request stream is not ending. #520

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

Merged
merged 3 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions source/h2_frames.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ int aws_h2_encode_data_frame(
/* Use a sub-buffer to limit where body can go */
struct aws_byte_buf body_sub_buf =
aws_byte_buf_from_empty_array(output->buffer + output->len + bytes_preceding_body, max_body);

/* Read body into sub-buffer */
if (aws_input_stream_read(body_stream, &body_sub_buf)) {
*body_failed = true;
Expand All @@ -401,14 +400,14 @@ int aws_h2_encode_data_frame(
if (body_sub_buf.len < body_sub_buf.capacity) {
/* Body stream was unable to provide as much data as it could have */
*body_stalled = true;

if (body_sub_buf.len == 0) {
/* This frame would have no useful information, don't even bother sending it */
goto handle_nothing_to_send_right_now;
}
}
}

if (body_sub_buf.len == 0 && !(flags & AWS_H2_FRAME_F_END_STREAM)) {
/* This frame would have no useful information, don't even bother sending it */
goto handle_nothing_to_send_right_now;
}

ENCODER_LOGF(
TRACE,
encoder,
Expand Down
5 changes: 5 additions & 0 deletions tests/fuzz/fuzz_h2_decoder_correct.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

/* Allow body to exceed available space. Data encoder should just write what it can fit */
struct aws_input_stream *body = aws_input_stream_new_from_cursor(allocator, &input);
if (input.len == 0) {
/* In case of empty body, make sure the end stream flag to be set, other wise, no frames should be
* generated to decode. */
body_ends_stream = true;
}

bool body_complete;
bool body_stalled;
Expand Down
Loading