Skip to content

[BUG] nil platform manifest entry causes a panic in DiscoverPlatformsFromReference #1645

Description

@false200

Version of copa

main built from source

Expected Behavior

When copa patches a multi platform image whose manifest index contains a child entry that has no platform field, copa should skip that entry and keep discovering the remaining valid platforms.

Actual Behavior

copa crashes with a nil pointer dereference panic.

The code path is DiscoverPlatformsFromReference in pkg/buildkit/buildkit.go around lines 399 and 400. The branch that is meant to skip entries with a missing or unknown platform still reads m.Platform.OS and m.Platform.Architecture inside the log call. Go evaluates those arguments before the log function runs, and logrus evaluates them regardless of the current log level, so a nil platform is dereferenced and the process panics.

The failing code looks like this

if m.Platform == nil || m.Platform.OS == "unknown" || m.Platform.Architecture == "unknown" {
    log.Debugf("Skipping manifest with unknown platform: %s/%s", m.Platform.OS, m.Platform.Architecture)
    continue
}

The panic message is

runtime error invalid memory address or nil pointer dereference

A manifest index can legitimately contain entries with no platform field, for example attestation or provenance entries, so any such image triggers this.

Steps To Reproduce

  1. Build copa from source on main
  2. Prepare a multi platform image whose index has at least one child manifest with no platform field, for example an attestation entry
  3. Run copa patch on that image with no report so the platform discovery path runs
  4. copa panics instead of skipping the entry and patching the valid platforms

Are you willing to submit PRs to contribute to this bug fix?

  • Yes, I am willing to implement it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions