deltas: Handle untrusted checksums faster and more robustly

When reworking the ostree core [to use O_TMPFILE](https://github.com/ostreedev/ostree/pull/369),
I hit an issue in the way the untrusted delta codepath ends up trying
to re-open the file to checksum it.  That's not possible with
`O_TMPFILE` since the fd (which we opened `O_WRONLY`) is the only
accessible reference to the content.

Fix this by changing the delta processing code to update a checksum as
we're doing writes, which is also faster, and ends up simplifying the
code as well.

What would be an even larger simplification here is if we e.g. used a
separate thread calling `write_object()` or something like that; the
main issue I see there is somehow bridging the fact that function
wants a `GInputStream*` but the delta code is generating stream of
writes.

Closes: #392
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2016-07-29 16:03:28 +00:00
1 parent fb0bf27d10
commit 6ffcb24d22
5 files changed
+126 -195

No files matched your search

+5 -5
View File
@@ -203,9 +203,9 @@ ostree_validate_rev (const char *rev,
return ret;
}
static GVariant *
file_header_new (GFileInfo *file_info,
GVariant *xattrs)
GVariant *
_ostree_file_header_new (GFileInfo *file_info,
GVariant *xattrs)
{
guint32 uid;
guint32 gid;
@@ -518,7 +518,7 @@ ostree_raw_file_to_content_stream (GInputStream *input,
g_autoptr(GVariant) file_header = NULL;
guint64 header_size;
file_header = file_header_new (file_info, xattrs);
file_header = _ostree_file_header_new (file_info, xattrs);
if (!header_and_input_to_stream (file_header,
input,
out_input,
@@ -772,7 +772,7 @@ ostree_checksum_file_from_input (GFileInfo *file_info,
{
g_autoptr(GVariant) file_header = NULL;
file_header = file_header_new (file_info, xattrs);
file_header = _ostree_file_header_new (file_info, xattrs);
if (!write_file_header_update_checksum (NULL, file_header, checksum,
cancellable, error))