Skip to content

Bump AWS_EVENT_STREAM_MAX_HEADERS_SIZE #123

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 1 commit into from
Feb 13, 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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,23 @@ git clone [email protected]:awslabs/aws-c-event-stream.git
cmake -S aws-c-event-stream -B aws-c-event-stream/build -DCMAKE_INSTALL_PREFIX=<install-path> -DCMAKE_PREFIX_PATH=<install-path>
cmake --build aws-c-event-stream/build --target install
```

## Encoding

Event stream encoding provides bidirectional communication between a client and a server.

Each message consists of two sections: the prelude and the data. The prelude consists of:
1. The total byte length of the message
2. The combined byte length of all headers

The data section consists of:
1. Headers
2. Payload

Each section ends with a 4-byte big-endian CRC32 checksum. The message checksum is for both the prelude section and the data section.

Total message overhead, including the prelude and both checksums, is 16 bytes.

The following diagram shows the components that make up a message and a header. There are multiple headers per message.

![Encoding Diagram](docs/encoding.png)
Binary file added docs/images/encoding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 13 additions & 9 deletions include/aws/event-stream/event_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ AWS_PUSH_SANE_WARNING_LEVEL
#define AWS_C_EVENT_STREAM_PACKAGE_ID 4
/* max message size is technically unbounded on the client side, and validated on the server side but we don't want to
* allocate large buffers in case of bugs. 256 MB is a reasonably large buffer size limit. Current service-
* side max is 24 MB, likely to increase in future. */
* side max is 24 MB, likely to increase in future.
* This is encoded on the wire in 4 bytes, and could technically be larger (up to INT32_MAX). */
#define AWS_EVENT_STREAM_MAX_MESSAGE_SIZE (256 * 1024 * 1024)

/* max header size is 128kb */
#define AWS_EVENT_STREAM_MAX_HEADERS_SIZE (128 * 1024)
/* Max total size for headers.
* This is encoded on the wire in 4 bytes, and could technically be larger (up to INT32_MAX). */
#define AWS_EVENT_STREAM_MAX_HEADERS_SIZE (AWS_EVENT_STREAM_MAX_MESSAGE_SIZE)

/* Max header name length is 127 bytes */
/* Max header name length is 127 bytes.
* This is encoded on the wire in 1 byte, it cannot change. */
#define AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX (INT8_MAX)

/* Max header static value length is 16 bytes */
#define AWS_EVENT_STREAM_HEADER_STATIC_VALUE_LEN_MAX (16)
/* Max header value length is 32767 bytes.
* This is encoded on the wire in 2 bytes, it cannot change. */
#define AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX (INT16_MAX)

enum aws_event_stream_errors {
AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_EVENT_STREAM_PACKAGE_ID),
Expand Down Expand Up @@ -89,11 +93,11 @@ enum aws_event_stream_header_value_type {

struct aws_event_stream_header_value_pair {
uint8_t header_name_len;
char header_name[INT8_MAX];
char header_name[AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX];
enum aws_event_stream_header_value_type header_value_type;
union {
uint8_t *variable_len_val;
uint8_t static_val[AWS_EVENT_STREAM_HEADER_STATIC_VALUE_LEN_MAX];
uint8_t *variable_len_val; /* for variable-size types (STRING, BYTE_BUF)*/
uint8_t static_val[16]; /* largest fixed-size types are 16 bytes (INT64, UUID, TIMESTAMP) */
} header_value;

uint16_t header_value_len;
Expand Down
14 changes: 9 additions & 5 deletions source/event_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ int aws_event_stream_add_string_header(
AWS_FATAL_PRECONDITION(headers);
AWS_RETURN_ERROR_IF(
name_len <= AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(value_len <= INT16_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(
value_len <= AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
struct aws_event_stream_header_value_pair header = {
.header_name_len = name_len,
.header_value_len = value_len,
Expand All @@ -720,7 +721,7 @@ struct aws_event_stream_header_value_pair aws_event_stream_create_string_header(
struct aws_byte_cursor name,
struct aws_byte_cursor value) {
AWS_FATAL_PRECONDITION(name.len <= AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX);
AWS_FATAL_PRECONDITION(value.len <= INT16_MAX);
AWS_FATAL_PRECONDITION(value.len <= AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX);

struct aws_event_stream_header_value_pair header = {
.header_value_type = AWS_EVENT_STREAM_HEADER_STRING,
Expand Down Expand Up @@ -917,7 +918,8 @@ int aws_event_stream_add_string_header_by_cursor(

AWS_FATAL_PRECONDITION(headers);
AWS_EVENT_STREAM_VALIDATE_HEADER_NAME_CURSOR(name);
AWS_RETURN_ERROR_IF(value.len <= INT16_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(
value.len <= AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);

struct aws_event_stream_header_value_pair header = {
.header_name_len = (uint8_t)name.len,
Expand All @@ -937,7 +939,8 @@ int aws_event_stream_add_byte_buf_header_by_cursor(

AWS_FATAL_PRECONDITION(headers);
AWS_EVENT_STREAM_VALIDATE_HEADER_NAME_CURSOR(name);
AWS_RETURN_ERROR_IF(value.len <= INT16_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(
value.len <= AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);

struct aws_event_stream_header_value_pair header = {
.header_name_len = (uint8_t)name.len,
Expand Down Expand Up @@ -1028,7 +1031,8 @@ int aws_event_stream_add_bytebuf_header(
AWS_FATAL_PRECONDITION(name);
AWS_RETURN_ERROR_IF(
name_len <= AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(value_len <= INT16_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);
AWS_RETURN_ERROR_IF(
value_len <= AWS_EVENT_STREAM_HEADER_VALUE_LEN_MAX, AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN);

struct aws_event_stream_header_value_pair header = {
.header_name_len = name_len,
Expand Down