fix(toxics/slicer): never overflow the stack or slice out of range - #770
Open
lenamonj wants to merge 1 commit into
Open
fix(toxics/slicer): never overflow the stack or slice out of range#770lenamonj wants to merge 1 commit into
lenamonj wants to merge 1 commit into
Conversation
chunk() recursed on an interval that never shrank when average_size was 0, the value the CLI sends when no attributes are given, so the first byte through the proxy overflowed the stack; with size_variation at or above average_size the jittered midpoint could leave the piece and Pipe panicked with slice bounds out of range (Shopify#541). Return the piece whole for a non-positive average_size or a piece under two bytes, and clamp the midpoint inside the piece.
Author
|
I have signed the CLA! |
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.
Fixes #541.
SlicerToxic.chunkrecurses on an interval that never shrinks whenaverage_sizeis 0, which is whattoxiproxy-cli toxic add -t slicer <proxy>sends when no attributes are given: the first byte through the proxy ends the server withfatal error: stack overflow. Withsize_variationat or aboveaverage_sizethe jittered midpoint can land outside the piece, andPipepanics withslice bounds out of range(#541).chunknow returns the piece whole whenaverage_sizeis 0 or less or the piece is under two bytes, and clamps the midpoint inside the piece so both halves are shorter than it. Slicing for attributes that already worked is unchanged.The new test drives nine attribute pairs, including the zero defaults and
size_variation > average_size, over six payload sizes and checks the pieces reassemble byte for byte. On main it dies with the stack overflow.make test,go vet ./...pass.