mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
gvariant-serialiser: Convert endianness of offsets
The array of offsets is little-endian, even on big-endian architectures
like s390x.
Fixes: ade71fb5
"gvariant: Don’t allow child elements to overlap with each other"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2839
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
8b80c451a5
commit
ba2137b0d9
@ -714,17 +714,19 @@ gvs_variable_sized_array_n_children (GVariantSerialised value)
|
||||
/* Find the index of the first out-of-order element in @data, assuming that
|
||||
* @data is an array of elements of given @type, starting at index @start and
|
||||
* containing a further @len-@start elements. */
|
||||
#define DEFINE_FIND_UNORDERED(type) \
|
||||
#define DEFINE_FIND_UNORDERED(type, le_to_native) \
|
||||
static gsize \
|
||||
find_unordered_##type (const guint8 *data, gsize start, gsize len) \
|
||||
{ \
|
||||
gsize off; \
|
||||
type current, previous; \
|
||||
type current_le, previous_le, current, previous; \
|
||||
\
|
||||
memcpy (&previous, data + start * sizeof (current), sizeof (current)); \
|
||||
memcpy (&previous_le, data + start * sizeof (current), sizeof (current)); \
|
||||
previous = le_to_native (previous_le); \
|
||||
for (off = (start + 1) * sizeof (current); off < len * sizeof (current); off += sizeof (current)) \
|
||||
{ \
|
||||
memcpy (¤t, data + off, sizeof (current)); \
|
||||
memcpy (¤t_le, data + off, sizeof (current)); \
|
||||
current = le_to_native (current_le); \
|
||||
if (current < previous) \
|
||||
break; \
|
||||
previous = current; \
|
||||
@ -732,10 +734,11 @@ gvs_variable_sized_array_n_children (GVariantSerialised value)
|
||||
return off / sizeof (current) - 1; \
|
||||
}
|
||||
|
||||
DEFINE_FIND_UNORDERED (guint8);
|
||||
DEFINE_FIND_UNORDERED (guint16);
|
||||
DEFINE_FIND_UNORDERED (guint32);
|
||||
DEFINE_FIND_UNORDERED (guint64);
|
||||
#define NO_CONVERSION(x) (x)
|
||||
DEFINE_FIND_UNORDERED (guint8, NO_CONVERSION);
|
||||
DEFINE_FIND_UNORDERED (guint16, GUINT16_FROM_LE);
|
||||
DEFINE_FIND_UNORDERED (guint32, GUINT32_FROM_LE);
|
||||
DEFINE_FIND_UNORDERED (guint64, GUINT64_FROM_LE);
|
||||
|
||||
static GVariantSerialised
|
||||
gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
|
Loading…
Reference in New Issue
Block a user