-
Notifications
You must be signed in to change notification settings - Fork 98
fix(storage): add bounds validation in Footer::Parse #2171
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 |
|---|---|---|
|
|
@@ -80,9 +80,16 @@ Footer::Parse(StreamReader& reader) { | |
| } | ||
| // no popseek, continue to parse | ||
|
|
||
| if (length < 20) { | ||
| reader.PopSeek(); | ||
| return nullptr; | ||
| } | ||
| uint64_t metadata_string_length = 0; | ||
| std::vector<char> string_buffer(length); | ||
| memcpy(&metadata_string_length, meta_buffer.data() + 8, 8); | ||
| if (metadata_string_length > length - 20) { | ||
|
Collaborator
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. Bounds check is correct. Passing gives
Contributor
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. Confirmed — |
||
| reader.PopSeek(); | ||
| return nullptr; | ||
| } | ||
| std::string metadata_string(meta_buffer.data() + 16, metadata_string_length); | ||
| uint32_t checksum; | ||
| memcpy(&checksum, meta_buffer.data() + 16 + metadata_string_length, 4); | ||
|
|
||
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 ordering: this
length < 20early-return runs before anylength - 20evaluation, so the unsigned subtraction below cannot underflow.