After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 793394 - Automatically realign data passed to g_variant_new_from_bytes() or g_variant_new_from_data()
Automatically realign data passed to g_variant_new_from_bytes() or g_variant_...
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gvariant
2.55.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-02-12 16:10 UTC by Philip Withnall
Modified: 2018-05-24 20:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Reproducer (1.33 KB, text/plain)
2018-02-13 15:53 UTC, Philip Withnall
Details

Description Philip Withnall 2018-02-12 16:10:12 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.
Comment 1 Philip Withnall 2018-02-13 15:53:46 UTC
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).
Comment 2 Nick Richards 2018-02-13 18:44:16 UTC
This problem absolutely exists in programs in the wild, such as https://gitlab.gnome.org/danigm/fractal/issues/88
Comment 3 Sebastian Dröge (slomo) 2018-02-14 09:57:20 UTC
This is basically https://bugzilla.gnome.org/show_bug.cgi?id=790030 again, yes.
Comment 4 GNOME Infrastructure Team 2018-05-24 20:13:44 UTC
-- 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.