Skip to content

fix(toxics/slicer): never overflow the stack or slice out of range - #770

Open
lenamonj wants to merge 1 commit into
Shopify:mainfrom
lenamonj:slicer-termination
Open

fix(toxics/slicer): never overflow the stack or slice out of range#770
lenamonj wants to merge 1 commit into
Shopify:mainfrom
lenamonj:slicer-termination

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #541.

SlicerToxic.chunk recurses on an interval that never shrinks when average_size is 0, which is what toxiproxy-cli toxic add -t slicer <proxy> sends when no attributes are given: the first byte through the proxy ends the server with fatal error: stack overflow. With size_variation at or above average_size the jittered midpoint can land outside the piece, and Pipe panics with slice bounds out of range (#541).

chunk now returns the piece whole when average_size is 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.

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.
@lenamonj

lenamonj commented Sep 7, 2026

Copy link
Copy Markdown
Author

I have signed the CLA!

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.

panic: runtime error: slice bounds out of range [808:773]

1 participant