ostree_raw_file_to_content_stream: Make size default to 0
authorSimon McVittie <smcv@collabora.com>
Fri, 17 Mar 2023 12:53:42 +0000 (12:53 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 17 Mar 2023 12:53:42 +0000 (12:53 +0000)
Some existing code calls into ostree_raw_file_to_content_stream() with
file objects that do not have the standard::size attribute. Since GLib
2.76.0, attempting to access the size of such an object raises a
critical warning. Handle this more gracefully by defaulting the size
to 0, like earlier versions of GLib did.

Signed-off-by: Simon McVittie <smcv@collabora.com>
src/libostree/ostree-core.c

index 0d1b0d5d0ca8498e7b4a5cc9d42d58ac84ebb2c7..f2f8c7a525fc187c620bbbc7940db238c854b30d 100644 (file)
@@ -550,7 +550,9 @@ ostree_raw_file_to_content_stream (GInputStream       *input,
   g_autoptr(GBytes) file_header = _ostree_file_header_new (file_info, xattrs);
   *out_input = header_and_input_to_stream (file_header, input);
   if (out_length)
-    *out_length = g_bytes_get_size (file_header) + g_file_info_get_size (file_info);
+    *out_length = g_bytes_get_size (file_header);
+  if (out_length && g_file_info_has_attribute (file_info, "standard::size"))
+    *out_length += g_file_info_get_size (file_info);
   return TRUE;
 }