Fix unbounded inflate parsing binary fragments#76
Merged
Conversation
When parsing a binary fragment, the library attempted to decompress the patch data before checking the expected size and without specifying any limit. This allowed a malicious patch to include an "inflate bomb" as a binary fragment, forcing the library to allocate excessive memory during parsing. The BinaryFragment type now stores the raw compressed data at parse time and provides a separate method to get a reader for the decompressed data. The reader limits the decompressed size to the declared size in the fragment. This is an API break, but I expect very few clients interact with binary fragment data directly. This fixes the unbounded inflate during parsing and also limits the memory allocated by the library during an apply to a copy buffer. However, applying a patch can still write large amounts of data to the client-provided writer in ways the client can't easily prevent. A future commit will enforce limits at apply time to fix this.
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.
When parsing a binary fragment, the library attempted to decompress the patch data before checking the expected size and without specifying any limit. This allowed a malicious patch to include an "inflate bomb" as a binary fragment, forcing the library to allocate excessive memory during parsing.
The BinaryFragment type now stores the raw compressed data at parse time and provides a separate method to get a reader for the decompressed data. The reader limits the decompressed size to the declared size in the fragment. This is an API break, but I expect very few clients interact with binary fragment data directly.
This fixes the unbounded inflate during parsing and also limits the memory allocated by the library during an apply to a copy buffer. However, applying a patch can still write large amounts of data to the client-provided writer in ways the client can't easily prevent. A future commit will enforce limits at apply time to fix this.