-
Notifications
You must be signed in to change notification settings - Fork 0
3622: [C] Fix negative length validation in binary decoding #27
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,10 @@ static int read_bytes(avro_reader_t reader, char **bytes, int64_t * len) | |
| int rval; | ||
| check_prefix(rval, read_long(reader, len), | ||
| "Cannot read bytes length: "); | ||
| if (*len < 0) { | ||
| avro_set_error("Invalid bytes length: %" PRId64, *len); | ||
| return EINVAL; | ||
| } | ||
| *bytes = (char *) avro_malloc(*len + 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤖 Was this useful? React with 👍 or 👎
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:security; feedback:The Augment AI reviewer is correct! A specially crafted Avro file with a really big length value will lead to trying to allocate a lot of memory and possible crash due to out-of-memory error. |
||
| if (!*bytes) { | ||
| avro_set_error("Cannot allocate buffer for bytes value"); | ||
|
|
@@ -175,6 +179,10 @@ static int read_string(avro_reader_t reader, char **s, int64_t *len) | |
| int rval; | ||
| check_prefix(rval, read_long(reader, &str_len), | ||
| "Cannot read string length: "); | ||
| if (str_len < 0) { | ||
| avro_set_error("Invalid string length: %" PRId64, str_len); | ||
| return EINVAL; | ||
| } | ||
| *len = str_len + 1; | ||
| *s = (char *) avro_malloc(*len); | ||
| if (!*s) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to see negative-length validation added for
read_bytes/read_string. Note thatskip_bytes(and thusskip_string) still accepts a decoded negative length and passes it toAVRO_SKIP, which could behave badly on malformed input.🤖 Was this useful? React with 👍 or 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:useful; category:security; feedback:The Augment AI reviewer is correct! The same kind of problem as the fixed ones could be seen in the skip_bytes() method. It should be fixed the same way as the others. Prevents a security attack by crafting an Avro file with negative length for a field with a Bytes schema.