Repository navigation
mutator: limit Any unpacking to the post-processing depth - #302
Open
radhika1314 wants to merge 1 commit into
Open
radhika1314 wants to merge 1 commit into
radhika1314 wants to merge 1 commit into
Conversation
UnpackAny unpacked google.protobuf.Any payloads all the way down. A nested Any is parsed as a fresh message at every level, so the parser recursion limit does not apply, and every unpacked level keeps a copy of the payload below it. Fix, Mutate and CrossOver therefore cost O(depth * size) memory and time on a deeply nested Any chain: a 900 KB input took 8.3 s and 1.9 GB of RSS in Mutator::Fix. PostProcessing::Run already drops everything deeper than kMaxInitializeDepth, so stop unpacking at the same depth. Output for inputs within the limit is unchanged; the same 900 KB input now takes 16 ms and 188 MB.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Repro: build a google.protobuf.Any chain nested 20000 deep (about 900 KB on the wire) and pass it to Mutator::Fix, which LoadProtoInput runs on every input. On the current tree that takes 8.3 s and 1.9 GB of peak RSS; a 225 KB chain already needs 586 MB. The nested value is parsed as a fresh message at each level, so the parser recursion limit does not apply.
Cause: UnpackAny unpacks every level, and each unpacked level keeps a copy of the payload below it, so memory and time are O(depth * size). PostProcessing::Run then drops everything deeper than kMaxInitializeDepth anyway.
Fix: stop unpacking at the same depth PostProcessing::Run stops at. Output for inputs within the limit is unchanged: the new DeepAny test pins the depth at which post processing truncates a nested Any chain and gives the same result with and without the change. With the patch the 900 KB input is fixed in 16 ms and 188 MB.