dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

panic when trying to deserialize a dict back into zvariant::Value #272

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @oknozor on Apr 20, 2022, 13:51

Hello I have some trouble with dict and serialization I am not sure but this might be a bug. Here is a simple reproducer :

#[derive(SerializeDict, Type, Debug)]
#[zvariant(signature = "a{sv}")]
struct Dummy {
    one: String,
    two: String,
    three: i16,
}

#[test]
fn serialize() {
    let _struct = Dummy {
        one: "one".to_string(),
        two: "two".to_string(),
        three: 14,
    };
    let context = EncodingContext::<LE>::new_dbus(0);
    let bytes = to_bytes(context.clone(), &_struct).unwrap();
    // Panics here !
    let value: Value = from_slice(&bytes, context).unwrap();
}

This produces the following error :

Message("invalid value: character `\0`, expected D-Bus string type must not contain interior null bytes")

Is this expected ?

zeenix commented 2 years ago

As said on the Matrix channel, Value has a specific encoding (VARIANT type of D-Bus) so you can't decode a non-VARIANT as Value directly.