mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-16 23:48:21 +01:00
gvariant: Don’t allow child elements of a tuple to overlap each other
This is similar to the earlier commit which prevents child elements of a variable-sized array from overlapping each other, but this time for tuples. It is based heavily on ideas by William Manley. Tuples are slightly different from variable-sized arrays in that they contain a mixture of fixed and variable sized elements. All but one of the variable sized elements have an entry in the frame offsets table. This means that if we were to just check the ordering of the frame offsets table, the variable sized elements could still overlap interleaving fixed sized elements, which would be bad. Therefore we have to check the elements rather than the frame offsets. The logic of checking the elements up to the index currently being requested, and caching the result in `ordered_offsets_up_to`, means that the algorithmic cost implications are the same for this commit as for variable-sized arrays: an O(N) cost for these checks is amortised out over N accesses to O(1) per access. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2121
This commit is contained in:
@@ -37,8 +37,11 @@ typedef struct
|
||||
* This guarantees that the bytes of element n don't overlap with any previous
|
||||
* element.
|
||||
*
|
||||
* This is both read and set by g_variant_serialised_get_child for arrays of
|
||||
* non-fixed-width types */
|
||||
* This is both read and set by g_variant_serialised_get_child() for arrays of
|
||||
* non-fixed-width types, and for tuples.
|
||||
*
|
||||
* Even when dealing with tuples, @ordered_offsets_up_to is an element index,
|
||||
* rather than an index into the frame offsets. */
|
||||
gsize ordered_offsets_up_to;
|
||||
} GVariantSerialised;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user