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

Treat some with_capacity calls as a hint. #394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kinetiknz
Copy link
Collaborator

In many places, the existing code uses with_capacity to preallocate a container in preparation as an optimization for parsing the following fields. In cases where the capacity is read directly from a field in the file and passed to with_capacity, it's trivial for an invalid file to trigger a controlled OOM crash by specifying a sufficiently large size.

This is intended to fix the crash mentioned in BMO 1813063 comment 14, triggered by a fuzzer generated file containing an stsd box reporting 738197505 entries in the sample description table (but only containing 1).

I've replaced each case where we read a u32 or larger field directly from the file and use it as a size hint for with_capacity to calls to the trivial wrappers vec_with_capacity_hint and hashmap_with_capacity_hint that limit the maximum preallocation size to the arbitrary value of 1MB CAPACITY_HINT_LIMIT.

The code uses with_capacity to preallocate a structure in preparation
for parsing the following fields.  In cases where we read the expected
size as a u32 or larger field directly from the file, treat the expected
size as a hint and only allow preallocating up to an (arbitrary)
`CAPACITY_HINT_LIMIT`.
@kinetiknz kinetiknz self-assigned this Feb 8, 2023
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