Skip to content

New() can panic on OCI specs with a missing root section #902

Description

@Utkarsh-sharma47

Description

New() currently validates that the parsed OCI spec contains a linux section, but does not validate that spec.Root is present.

A syntactically valid but structurally incomplete config.json, such as:

{
  "linux": {}
}

can therefore reach code paths that dereference spec.Root.Path, resulting in a nil pointer panic instead of returning a validation error.

I also found that when valid unikernel annotations are present, New() can return successfully while u.Spec.Root == nil, leaving an invalid Unikontainer that may panic later.

Relevant code

New() currently checks:

if spec == nil || spec.Linux == nil {
    return nil, fmt.Errorf("invalid OCI spec: linux section is required")
}

but GetUnikernelConfig() later uses:

rootFSDir := spec.Root.Path

and other paths such as InitialSetup() and Exec() also access u.Spec.Root.Path.

Minimal reproducer

Create a bundle containing:

{
  "linux": {}
}

as config.json and call New() with that bundle.

Actual behavior

urunc can panic with a nil pointer dereference when the configuration fallback path accesses spec.Root.Path.

A spec containing valid unikernel annotations but no root section can also be accepted by New(), leaving Spec.Root == nil.

Expected behavior

Structurally incomplete OCI specs should be be rejected with a validation error, for example:

invalid OCI spec: root section is required

Possible direction

Validate that spec.Root is present before returning from New() / Get(), alongside the existing validation of spec.Linux.

A regression test using a minimal spec with linux present and root missing could cover this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions