control: tags -1 + patch

* Philip Withnall [2020-06-15 23:25:18 +0200]:
> https://gitlab.gnome.org/GNOME/glib/-/issues/422
> 
> Nobody has yet found time to work on it; merge requests are welcome!

Here is a patch that works for me.
Handle arbitrary binary data in extended attribute values.

It's safe to assume an escaped string doesn't contain embedded null bytes,
but raw memory buffers (as returned by getxattr()) require more care.

If the length of the data to be escaped is known, use that knowledge instead
of invoking strlen().

Also correct an off-by-one error in hex_unescape_string()'s computation of
the output string length.
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -293,17 +293,15 @@
 }
 
 static char *
-hex_escape_string (const char *str, 
+hex_escape_buffer (const char *str, 
+                   size_t      len,
                    gboolean   *free_return)
 {
-  int num_invalid, i;
+  size_t num_invalid, i;
   char *escaped_str, *p;
   unsigned char c;
   static char *hex_digits = "0123456789abcdef";
-  int len;
 
-  len = strlen (str);
-  
   num_invalid = 0;
   for (i = 0; i < len; i++)
     {
@@ -340,6 +338,13 @@
 }
 
 static char *
+hex_escape_string (const char *str, 
+                   gboolean   *free_return)
+{
+  return hex_escape_buffer (str, strlen(str), free_return);
+}
+
+static char *
 hex_unescape_string (const char *str, 
                      int        *out_len, 
                      gboolean   *free_return)
@@ -377,10 +382,10 @@
       else
 	*p++ = str[i];
     }
-  *p++ = 0;
-
   if (out_len)
     *out_len = p - unescaped_str;
+  *p++ = 0;
+
   *free_return = TRUE;
   return unescaped_str;
 }
@@ -394,7 +399,7 @@
   char *escaped_val;
   gboolean free_escaped_val;
   
-  escaped_val = hex_escape_string (value, &free_escaped_val);
+  escaped_val = hex_escape_buffer (value, len, &free_escaped_val);
   
   g_file_info_set_attribute_string (info, gio_attr, escaped_val);
   

Reply via email to