Skip to content
Open
11 changes: 7 additions & 4 deletions registry/app/pkg/docker/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
registryTypes "github.com/harness/gitness/registry/types"
"github.com/harness/gitness/types"

"github.com/google/uuid"
"github.com/opencontainers/go-digest"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -139,10 +140,12 @@ func (app *App) GetBlobsContext(
OciBlobStore: nil,
}

// For reads and lazy replication
if result := app.bucketService.GetBlobStore(c, info.RegIdentifier, info.RootIdentifier, blobLocator.BlobID,
digest.Digest(info.Digest).String()); result != nil {
ctx.OciBlobStore = result.OciStore
if blobLocator.BlobID != 0 || blobLocator.GenericBlobID != uuid.Nil {
// For reads and lazy replication
if result := app.bucketService.GetBlobStore(c, info.RegIdentifier, info.RootIdentifier, blobLocator.BlobID,
digest.Digest(info.Digest).String()); result != nil {
ctx.OciBlobStore = result.OciStore
}
}
Comment on lines +143 to 149

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect BlobLocator type definition
echo "=== BlobLocator definition ==="
rg -n "type BlobLocator" --type go -A 10

echo ""
echo "=== GetBlobStore interface/function signatures ==="
rg -n "GetBlobStore" --type go -B 2 -A 5

echo ""
echo "=== Context: Show lines 143-149 in app.go ==="
sed -n '140,160p' registry/app/pkg/docker/app.go

Repository: abhinavcode/harness

Length of output: 4105


🏁 Script executed:

#!/bin/bash
# Check how GetBlobStore is implemented and handles blobID=0
echo "=== Searching for GetBlobStore implementation ==="
rg -n "GetBlobStore" --type go -A 15 | head -80

echo ""
echo "=== Check context around the problematic code to understand flow ==="
sed -n '130,160p' registry/app/pkg/docker/app.go

echo ""
echo "=== Check if there are other callers of GetBlobStore ==="
rg -n "GetBlobStore\(" --type go -B 2 -A 2

Repository: abhinavcode/harness

Length of output: 6678


GenericBlobID is checked in the guard but never forwarded to GetBlobStore.

The OR condition at line 143 enters the if-block when blobLocator.GenericBlobID != uuid.Nil (even when BlobID == 0), but GetBlobStore only accepts a blobID parameter of type any—there is no parameter for GenericBlobID. When BlobID is 0 and GenericBlobID is non-nil, the call passes a zero BlobID:

app.bucketService.GetBlobStore(c, info.RegIdentifier, info.RootIdentifier, blobLocator.BlobID, ...)

This results in either a wasted lookup (if GetBlobStore returns nil for ID 0) or unpredictable behavior depending on the implementation.

For OCI operations (in GetOciBlobsContext), GenericBlobID is irrelevant—only BlobID (the int64 field) is semantically meaningful. The condition should be simplified to blobLocator.BlobID != 0 to match what is actually consumed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@registry/app/pkg/docker/app.go` around lines 143 - 149, The guard is allowing
GenericBlobID to drive the branch but GetBlobStore only uses BlobID; update the
condition to only check blobLocator.BlobID != 0 (remove reference to
blobLocator.GenericBlobID) so we don't call app.bucketService.GetBlobStore with
a zero blob id; locate the block around GetOciBlobsContext and the call to
app.bucketService.GetBlobStore and change the if to rely solely on
blobLocator.BlobID to match the actual semantic use.


// Default read/write
Expand Down