Treat some with_capacity calls as a hint.#394
Open
kinetiknz wants to merge 1 commit intomozilla:masterfrom
Open
Treat some with_capacity calls as a hint.#394kinetiknz wants to merge 1 commit intomozilla:masterfrom
kinetiknz wants to merge 1 commit intomozilla:masterfrom
Conversation
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`.
ashleyz
approved these changes
Feb 10, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In many places, the existing code uses
with_capacityto 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 towith_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_capacityto calls to the trivial wrappersvec_with_capacity_hintandhashmap_with_capacity_hintthat limit the maximum preallocation size to the arbitrary value of 1MBCAPACITY_HINT_LIMIT.