ostree-blob-reader: Add error handling for invalid base64 blobs
authorPhilip Withnall <pwithnall@gnome.org>
Mon, 3 Aug 2026 15:30:28 +0000 (16:30 +0100)
committerPhilip Withnall <pwithnall@gnome.org>
Tue, 4 Aug 2026 12:10:00 +0000 (13:10 +0100)
One cannot base64 decode the empty string, so catch that case (which can
happen if asked to load a malformed key file) early before it causes an
assertion failure inside GLib.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
src/libostree/ostree-blob-reader-base64.c

index 6faa482027665a0f6d845757aa61d01eb8cbe006..2a621822587b3ba1ac4b83c371be2a8c505ae946 100644 (file)
@@ -71,9 +71,16 @@ ostree_blob_reader_base64_read_blob (OstreeBlobReader *self, GCancellable *cance
 
   if (line == NULL)
     return NULL;
+  else if (len == 0)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
+                           "Invalid base64 blob format");
+      return NULL;
+    }
 
   gsize n_elements;
   g_base64_decode_inplace (line, &n_elements);
+  g_assert (n_elements <= len);
   explicit_bzero (line + n_elements, len - n_elements);
 
   return g_bytes_new_take (g_steal_pointer (&line), n_elements);