Skip to content

bug: tracked targets always claim registry.Mounter and panic on non-remote targets #2278

Description

@TerryHowe

What is the problem?

graphTarget in cmd/oras/internal/display/status/track/target.go always defines Mount:

// Mount mounts a blob from a specified repository. This method is invoked only
// by the `*remote.Repository` target.
func (t *graphTarget) Mount(ctx context.Context, desc ocispec.Descriptor, fromRepo string, getContent func() (io.ReadCloser, error)) error {
	mounter := t.GraphTarget.(registry.Mounter)
	return mounter.Mount(ctx, desc, fromRepo, getContent)
}

As a result, every tracked target satisfies registry.Mounter, including OCI-layout and other non-remote targets. oras-go decides whether to mount by type-asserting the destination for registry.Mounter. A wrapped non-remote target therefore claims mount support, and if a mount is ever attempted the unchecked assertion panics rather than returning an error or falling back to copy.

Today this is masked because cp only sets MountFrom when both sides are remote (getMountPoint). That depends on a caller-side invariant, and any future caller (backup/restore, attach, a library refactor) that sets MountFrom against a tracked OCI-layout target would crash.

Proposed fix

Expose Mount only when the wrapped target supports it. referenceGraphTarget already does this for PushReference:

  • keep graphTarget without Mount
  • add a mounterGraphTarget wrapper returned by NewTarget only when gt.(registry.Mounter) succeeds
  • alternatively, use a checked assertion that returns errdef.ErrUnsupported, so oras-go falls back to copy

Add a unit test that wraps an oci.Store and asserts _, ok := tracked.(registry.Mounter); !ok.

oras-go v3 note

v3 keeps the same registry.Mounter type-assertion contract (registry/interfaces.go), and the code is unchanged on the v3 migration branch (#2002).

Activity

  1. added
    bug
    help wanted
    on Oct 23, 2026
  2. kocaemre commented on Oct 23, 2026

    @kocaemre
    Contributor

    I’d like to work on this. I’ll add a regression that checks tracked OCI-layout targets do not advertise registry.Mounter, keep mounting available for remote targets, then run the affected Go package tests and lint.

  3. wleeaf commented on Oct 23, 2026

    @wleeaf
    Contributor

    For whoever picks this up: the panic is reachable today, not only in theory. oras cp --force wraps the destination in contentutil.TraversingTarget after getMountPoint has set up MountFrom on the raw repository. The tracked graph target still claims registry.Mounter, so the type assertion in Mount fails. Against a local registry:2, run from a terminal (the TTY path uses the tracked target):

    oras cp --force localhost:5000/src:v1 localhost:5000/dst:v1
    panic: interface conversion: *contentutil.TraversingTarget is not registry.Mounter: missing method Mount
    

    Without --force, or without a TTY, it works. That case might be worth covering in the regression test too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions