Skip to content

Commit

Permalink
fix: make a copy of the bytes array before passing to the channel, fi…
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral authored Feb 27, 2024
1 parent 499b164 commit 73abc7a
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 73abc7a

Please sign in to comment.