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

Clamp Vec::with_capacity to 64KiB to avoid OOM #1545

Merged
merged 1 commit into from
Sep 12, 2022
Merged

Clamp Vec::with_capacity to 64KiB to avoid OOM #1545

merged 1 commit into from
Sep 12, 2022

Conversation

jkugelman
Copy link
Contributor

Fuzz testers love to muck with length fields and trigger OOM panics. This is documented in #1459.

This PR fixes the linked issue, though my solution is not the suggested one. Rather than adding a new combinator, I've updated many_m_n and count to clamp their Vec::with_capacity calls to 64KiB. This greatly reduces (though does not eliminate) the risk of OOM panics while still providing most of the benefit of preallocating memory.

Clamping initial capacity to 64KiB does not affect correctness. Nom will still read the full number of elements. The initial capacity is just a performance hint.

@Geal
Copy link
Collaborator

Geal commented Sep 12, 2022

That sounds good, it's an easy way to make it more reliable, thanks!

@Geal Geal merged commit 3645656 into rust-bakery:main Sep 12, 2022
@jkugelman jkugelman deleted the clamp-capacity branch September 12, 2022 19:58
@jkugelman
Copy link
Contributor Author

Follow-up fix: #1549

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