GNOME Bugzilla – Bug 793394
Automatically realign data passed to g_variant_new_from_bytes() or g_variant_new_from_data()
Last modified: 2018-05-24 20:13:44 UTC
If a byte array which is passed to g_variant_new_from_[bytes|data]() is not sufficiently aligned for the given GVariantType, a critical warning will be emitted: gvariant-serialiser.c:167:g_variant_serialised_check: assertion failed (alignment & (gsize) serialised.data == 0): (4 == 0) The caller can’t know what alignment the GVariantType is meant to have (it’s not exposed in public API) — and even if they were, making every caller of g_variant_new_from_[bytes|data]() realign their data amounts to a lot of code. It would be better if the realignment was done (only if needed) in gvariant-core.c, and documented. If callers care about speed, they can ensure their byte arrays are correctly aligned before passing them to GVariant. This also means we can eliminate the align_malloc() faff in glib/tests/gvariant.c, and partially revert commit 7b60708204354da877f7eda5150631223bba42f2.
Created attachment 368318 [details] Reproducer Here’s a little test program which will forcibly reproduce the problem (on any architecture, assuming it aligns string constants to anything other than 7- or 9-byte boundaries).
This problem absolutely exists in programs in the wild, such as https://gitlab.gnome.org/danigm/fractal/issues/88
This is basically https://bugzilla.gnome.org/show_bug.cgi?id=790030 again, yes.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1342.