Make mandatory properties from OCI specifications mandatory

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().
This commit is contained in:
Owen W. Taylor
2026-06-16 14:23:58 -04:00
committed by Sebastian Wick
parent 4d3f0bbb79
commit fa4b413c02
2 changed files with 19 additions and 6 deletions

View File

@@ -88,9 +88,9 @@ flatpak_oci_descriptor_free (FlatpakOciDescriptor *self)
}
static FlatpakJsonProp flatpak_oci_descriptor_props[] = {
FLATPAK_JSON_STRING_PROP (FlatpakOciDescriptor, mediatype, "mediaType"),
FLATPAK_JSON_STRING_PROP (FlatpakOciDescriptor, digest, "digest"),
FLATPAK_JSON_INT64_PROP (FlatpakOciDescriptor, size, "size"),
FLATPAK_JSON_MANDATORY_STRING_PROP (FlatpakOciDescriptor, mediatype, "mediaType"),
FLATPAK_JSON_MANDATORY_STRING_PROP (FlatpakOciDescriptor, digest, "digest"),
FLATPAK_JSON_MANDATORY_INT64_PROP (FlatpakOciDescriptor, size, "size"),
FLATPAK_JSON_STRV_PROP (FlatpakOciDescriptor, urls, "urls"),
FLATPAK_JSON_STRMAP_PROP (FlatpakOciDescriptor, annotations, "annotations"),
FLATPAK_JSON_LAST_PROP
@@ -127,6 +127,10 @@ flatpak_oci_manifest_descriptor_free (FlatpakOciManifestDescriptor *self)
g_free (self);
}
/* Note that according to the OCI image spec, architecture and os are mandatory
* elements of the `platform` object - but the platform object is itself optional,
* so we leave them marked optional here to avoid confusion.
*/
static FlatpakJsonProp flatpak_oci_manifest_platform_props[] = {
FLATPAK_JSON_STRING_PROP (FlatpakOciManifestPlatform, architecture, "architecture"),
FLATPAK_JSON_STRING_PROP (FlatpakOciManifestPlatform, os, "os"),
@@ -276,8 +280,11 @@ flatpak_oci_manifest_class_init (FlatpakOciManifestClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FlatpakJsonClass *json_class = FLATPAK_JSON_CLASS (klass);
static FlatpakJsonProp props[] = {
FLATPAK_JSON_STRUCT_PROP (FlatpakOciManifest, config, "config", flatpak_oci_descriptor_props),
FLATPAK_JSON_STRUCTV_PROP (FlatpakOciManifest, layers, "layers", flatpak_oci_descriptor_props),
FLATPAK_JSON_MANDATORY_STRUCT_PROP (FlatpakOciManifest, config, "config", flatpak_oci_descriptor_props),
/* Not marked as REQUIRED in the OCI spec, but also not marked OPTIONAL. A manifest
* without layers, is in any case, useless to us.
*/
FLATPAK_JSON_MANDATORY_STRUCTV_PROP (FlatpakOciManifest, layers, "layers", flatpak_oci_descriptor_props),
FLATPAK_JSON_STRMAP_PROP (FlatpakOciManifest, annotations, "annotations"),
FLATPAK_JSON_LAST_PROP
};
@@ -433,7 +440,7 @@ flatpak_oci_index_class_init (FlatpakOciIndexClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FlatpakJsonClass *json_class = FLATPAK_JSON_CLASS (klass);
static FlatpakJsonProp props[] = {
FLATPAK_JSON_STRUCTV_PROP (FlatpakOciIndex, manifests, "manifests", flatpak_oci_manifest_descriptor_props),
FLATPAK_JSON_MANDATORY_STRUCTV_PROP (FlatpakOciIndex, manifests, "manifests", flatpak_oci_manifest_descriptor_props),
FLATPAK_JSON_STRMAP_PROP (FlatpakOciIndex, annotations, "annotations"),
FLATPAK_JSON_LAST_PROP
};

View File

@@ -65,6 +65,8 @@ struct _FlatpakJsonProp
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRING, 0, 0, FLATPAK_JSON_PROP_FLAGS_MANDATORY }
#define FLATPAK_JSON_INT64_PROP(_struct, _field, _name) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_INT64 }
#define FLATPAK_JSON_MANDATORY_INT64_PROP(_struct, _field, _name) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_INT64, 0, 0, FLATPAK_JSON_PROP_FLAGS_MANDATORY }
#define FLATPAK_JSON_BOOL_PROP(_struct, _field, _name) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_BOOL }
#define FLATPAK_JSON_STRV_PROP(_struct, _field, _name) \
@@ -77,6 +79,10 @@ struct _FlatpakJsonProp
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_BOOLMAP }
#define FLATPAK_JSON_STRUCT_PROP(_struct, _field, _name, _props) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props}
/* MANDATORY_STRUCT_PROP is one that must be present when demarshalling */
#define FLATPAK_JSON_MANDATORY_STRUCT_PROP(_struct, _field, _name, _props) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props, 0, FLATPAK_JSON_PROP_FLAGS_MANDATORY}
/* OPT_STRUCT_PROP is one that is not emitted into the result when marshalling if it would be empty */
#define FLATPAK_JSON_OPT_STRUCT_PROP(_struct, _field, _name, _props) \
{ _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props, 0, FLATPAK_JSON_PROP_FLAGS_OPTIONAL}
#define FLATPAK_JSON_STRICT_STRUCT_PROP(_struct, _field, _name, _props) \