diff --git a/src/libpriv/rpmostree-rojig-assembler.c b/src/libpriv/rpmostree-rojig-assembler.c index bd817962..2f3df0bf 100644 --- a/src/libpriv/rpmostree-rojig-assembler.c +++ b/src/libpriv/rpmostree-rojig-assembler.c @@ -143,12 +143,9 @@ rojig_read_variant (const GVariantType *vtype, const struct stat *stbuf = archive_entry_stat (entry); if (!S_ISREG (stbuf->st_mode)) return glnx_null_throw (error, "Expected regular file for entry: %s", path); - if (stbuf->st_size > OSTREE_MAX_METADATA_SIZE) - { - g_autofree char *max_formatted = g_format_size (OSTREE_MAX_METADATA_SIZE); - g_autofree char *found_formatted = g_format_size (stbuf->st_size); - return glnx_null_throw (error, "Exceeded maximum size %s; %s is of size: %s", max_formatted, found_formatted, path); - } + if (!rpmostree_check_size_within_limit (stbuf->st_size, OSTREE_MAX_METADATA_SIZE, + path, error)) + return NULL; g_assert_cmpint (stbuf->st_size, >=, 0); const size_t total = stbuf->st_size; g_autofree guint8* buf = g_malloc (total); diff --git a/src/libpriv/rpmostree-util.c b/src/libpriv/rpmostree-util.c index 86517288..49b89e10 100644 --- a/src/libpriv/rpmostree-util.c +++ b/src/libpriv/rpmostree-util.c @@ -234,6 +234,20 @@ rpmostree_pkg_get_local_path (DnfPackage *pkg) } } +gboolean +rpmostree_check_size_within_limit (guint64 actual, + guint64 limit, + const char *subject, + GError **error) +{ + if (actual <= limit) + return TRUE; + g_autofree char *max_formatted = g_format_size (limit); + g_autofree char *found_formatted = g_format_size (actual); + return glnx_throw (error, "Exceeded maximum size %s; %s is of size: %s", + max_formatted, subject, found_formatted); +} + /* Convert a "traditional" path (normally from e.g. an RPM) into its final location in * ostree */ char* diff --git a/src/libpriv/rpmostree-util.h b/src/libpriv/rpmostree-util.h index 3ae33c83..228f7713 100644 --- a/src/libpriv/rpmostree-util.h +++ b/src/libpriv/rpmostree-util.h @@ -68,6 +68,12 @@ rpmostree_pkg_is_local (DnfPackage *pkg); char * rpmostree_pkg_get_local_path (DnfPackage *pkg); +gboolean +rpmostree_check_size_within_limit (guint64 actual, + guint64 limit, + const char *subject, + GError **error); + char* rpmostree_translate_path_for_ostree (const char *path);