Skip to content

Improve handling of null and missing elements in OCI JSON files - #6704

Merged
swick merged 3 commits into
flatpak:mainfrom
owtaylor:oci-json-null-missing
Jun 16, 2026
Merged

swick merged 3 commits into
flatpak:mainfrom
owtaylor:oci-json-null-missing

Conversation

@owtaylor

Copy link
Copy Markdown
Contributor
  • Consistently handle <property>: null in the input the same as a missing property.
  • Mark all properties required by the OCI specification as required; this eliminates a bunch of cases where we were assume that descriptor->digest was non-NULL, and potentially generating critical errors from g_return_if_fail()
  • Fix a case where strcmp() was called on a potentially NULL architecture value.

@swick swick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just a few details we should clean up before merging.

Comment thread common/flatpak-oci-signatures.c Outdated
}

if (signature->critical.identity.reference != NULL)
if (signature->critical.identity.reference != NULL) /* defensive: cannot be demarshaled as NULL */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we expect this to be non-NULL, an assert is the right tool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread common/flatpak-json.c
Comment on lines +62 to +64
/* We treat <property>: null the same as missing. While you could
* have JSON data structures where the distinction is significant, we
* don't need to handle any such.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This deserves to be in its own commit.

Comment thread common/flatpak-json-oci.c
for (i = 0; self->manifests[i] != NULL; i++)
{
if (strcmp (self->manifests[i]->platform.architecture, oci_arch) == 0)
if (g_strcmp0 (self->manifests[i]->platform.architecture, oci_arch) == 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This also seems different enough from making properties mandatory that it doesn't belong in the same commit.

owtaylor added 3 commits June 16, 2026 15:53
Mark all properties required by the OCI specification as required;
this eliminates a bunch of cases where we were assuming that
descriptor->digest was non-NULL, and potentially generating
critical errors from g_return_if_fail().
It's legitimate to have manifests listed in an image index that
have no platform object, and hence no architecture - avoid crashing
if we encounter such a manifest.
We were handling null properties the same as missing properties
*except* that the MANDATORY flag allowed null properties but
not missing properties. Fix this, so null is disallowed by
MANDATORY.

When checking signatures, the image identity could only have
been NULL if it was null in the input file - so replace a
conditional check on it being non-null with an assertion.
@owtaylor
owtaylor force-pushed the oci-json-null-missing branch from 30f6328 to fcae93b Compare June 16, 2026 20:04
@owtaylor

Copy link
Copy Markdown
Contributor Author

if () turned into an assertion and split into three logical commits.

@swick
swick added this pull request to the merge queue Jun 16, 2026
@swick

swick commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Merged via the queue into flatpak:main with commit 906affa Jun 16, 2026
11 checks passed
@swick
swick deleted the oci-json-null-missing branch June 16, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants