Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/distribution/registry/testregistry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (r *Registry) handleBlobUpload(w http.ResponseWriter, req *http.Request, pa
switch req.Method {
case http.MethodPost:
// Start upload
r.mu.RLock()
uploadID := fmt.Sprintf("upload-%d", len(r.blobs))
r.mu.RUnlock()
Comment on lines +72 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using RLock here still allows concurrent readers to generate duplicate upload IDs based on len(r.blobs).

Because RLock allows concurrent readers, multiple goroutines can observe the same len(r.blobs) and generate identical uploadIDs. To ensure uniqueness, this section should either use the exclusive mutex (mu.Lock/mu.Unlock) around ID generation, or switch to a different mechanism (e.g., atomic counter or UUID). As is, the map access is safe but the ID generation still has a race condition.

Comment on lines +72 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the RLock correctly prevents a data race when reading len(r.blobs), using len(r.blobs) to generate the uploadID can still lead to non-unique identifiers in a concurrent environment. Multiple concurrent requests could read the same len(r.blobs) value, resulting in identical uploadIDs. This could cause issues if clients expect unique Docker-Upload-UUIDs or if the Location header is used for subsequent operations that rely on a unique identifier. Consider using a universally unique identifier (UUID) generator (e.g., github.com/google/uuid) or an atomic counter to ensure that uploadIDs are unique across concurrent requests. This would provide a more robust and standard way to generate upload identifiers.

location := fmt.Sprintf("/v2/%s/blobs/uploads/%s", repo, uploadID)
w.Header().Set("Location", location)
w.Header().Set("Docker-Upload-UUID", uploadID)
Expand Down