Skip to content

Commit

Permalink
fix: make a copy of the bytes array before passing to the channel
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral authored and rfay committed Feb 25, 2024
1 parent d9d922f commit 9f5a0a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/dockerutil/dockerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,12 @@ func ComposeCmd(cmd *ComposeCmdOpts) (string, string, error) {

go func() {
for inOut.Scan() {
chanOut <- inOut.Bytes()
// Bytes() underlying array may be overwritten by the next call to Scan().
// Copy it to a new allocation to prevent corruption.
token := inOut.Bytes()
duplicate := make([]byte, len(token))
copy(duplicate, token)
chanOut <- duplicate
}
close(stopOut)
}()
Expand Down

0 comments on commit 9f5a0a1

Please sign in to comment.