Skip to content

Commit 8b73c2d

Browse files
tonistiigik8s-infra-cherrypick-robot
authored andcommitted
remotes: fix possible panic from WithMediaTypeKeyPrefix
As the same instance of a map is used in context and mutated directly, this leads to a situation where: - Calling WithMediaTypeKeyPrefix from parallel goroutines where the context was based on the same base context can trigger a panic. - A subcontext calling WithMediaTypeKeyPrefix changes the value for another context when they both originate from the same base context. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 1c4457e commit 8b73c2d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

core/remotes/handlers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"io"
25+
"maps"
2526
"strings"
2627
"sync"
2728

@@ -45,6 +46,7 @@ func WithMediaTypeKeyPrefix(ctx context.Context, mediaType, prefix string) conte
4546
var values map[string]string
4647
if v := ctx.Value(refKeyPrefix{}); v != nil {
4748
values = v.(map[string]string)
49+
values = maps.Clone(values)
4850
} else {
4951
values = make(map[string]string)
5052
}

0 commit comments

Comments
 (0)