Why GVariant? (Re: Starting the kdbus discussions

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 3 05:10:05 PST 2014


On 02/01/14 15:37, Lennart Poettering wrote:
> On Thu, 02.01.14 16:16, rony (rony at wu.ac.at) wrote:
>>> For security reasons it is always a good idea to enforce certain things
>>> on the data you transfer, like compatibility with C strings or UTF-8
>>> validity.
> 
>> Are you sure? AFAIK dbus allows the transport of UTF-8 encoded
>> strings, which AFAIK may contain nul byte characters.
> 
> Yes I am sure.

Lennart is correct. The 's' type in the D-Bus type system is intended
for *text* strings. It denotes a string of zero or more Unicode
codepoints other than U+0000, encoded in UTF-8 without overlong sequences.

In other words, there are many byte sequences that 's' is not allowed to
carry: non-UTF-8 is excluded, UTF-8 with overlong sequences is excluded,
long UTF-8 sequences that would expand to a character of index 0x110000
or greater are excluded (because Unicode codepoints are defined to stop
at U+10FFFF), and any valid UTF-8 that happens to include U+0000
(encoded as "\0") is excluded.

Use a byte array, 'ay', if you want to transport arbitrary bytestrings
that are not necessarily "text" (including embedded "\0", legacy 8-bit
encodings, UTF-16, UTF-32, or byte blobs of no known encoding).

As far as I know, every valid D-Bus 's' is a valid GVariant 's', and
vice versa.

    S



More information about the dbus mailing list