Repository navigation
fix: clone byte slices in NewReusableReadCloser to avoid sharing caller memory (fixes #795) - #797
Merged
Mzack9999 merged 2 commits intoOct 23, 2026
Conversation
…er memory - Use bytes.Clone for []byte, *[]byte, and *bytes.Buffer to prevent mutating caller slices during reset - Fixes projectdiscovery#795 - Add unit tests verifying slice isolation across mutations, multiple readers, and nil pointers
TassioSales
force-pushed
the
fix/reusable-read-closer-copy-slice
branch
from
October 21, 2026 00:32
5f2a885 to
18634e3
Compare
Mzack9999
approved these changes
Oct 23, 2026
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.
Closes #795
Summary
When NewReusableReadCloser was constructed with []byte, *[]byte, or *bytes.Buffer, it wrapped the caller's slice directly without copying (
eadBuf = *bytes.NewBuffer(body)).
Upon reaching EOF,
eset() calls io.Copy(r.readBuf, r.backBuf), writing the buffer back into
eadBuf and mutating the caller's underlying slice. Consequently:
etryablehttp's request retries and dumps, as reported in NewReusableReadCloser shares the caller's byte slice #795 and nuclei#7878).
Changes
eader/reusable_read_closer_test.go verifying slice isolation across caller mutations, multiple readers from the same slice, and nil pointers.