Skip to content
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

ref: micro-optimise by reserving buffer size #803

Merged
merged 3 commits into from
Mar 1, 2023
Merged

ref: micro-optimise by reserving buffer size #803

merged 3 commits into from
Mar 1, 2023

Conversation

flub
Copy link
Contributor

@flub flub commented Feb 28, 2023

Before going into the loop we may as well make sure to reserve enough
space for the entire buffer. Otherwise we could be allocating
multiple times.

This does not change the total allocated size.

Before going into the loop we may as well make sure to reserve enough
space for the entire buffer.  Otherwise we could be allocating
multiple times.

This does not change the total allocated size.
@flub
Copy link
Contributor Author

flub commented Feb 28, 2023

Test failures are due to flaky tests that will be fixed in either #799 or #804.

@@ -93,6 +93,7 @@ pub(crate) async fn read_lp(
};
let mut reader = reader.take(size);
let size = usize::try_from(size).context("frame larger than usize")?;
buffer.reserve(size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be limited, I can now easily attack your machine by putting a crazy value here, and causing an OOM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that I wasn't at all changing how much is being allocated, this attack already existed. To be fair I also faultily assumed MAX_MESSAGE_SIZE was already being respected while it obviously wasn't.

So fair shout, MAX_MESSAGE_SIZE wasn't being checked yet so may as well improve this.

@flub flub requested a review from dignifiedquire March 1, 2023 09:23
@flub flub merged commit fe97e4d into main Mar 1, 2023
@flub flub deleted the flub/reserve-buf branch March 1, 2023 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants