Bugfix, GVariant: missing padding for fixed-size tuples. 36/92336/1 accepted/tizen/3.0/common/20161114.110504 accepted/tizen/3.0/ivi/20161028.151429 accepted/tizen/3.0/mobile/20161028.143348 accepted/tizen/3.0/tv/20161028.143614 accepted/tizen/3.0/wearable/20161028.150918 accepted/tizen/common/20161017.170121 accepted/tizen/ivi/20161017.075855 accepted/tizen/mobile/20161017.075813 accepted/tizen/tv/20161017.075825 accepted/tizen/wearable/20161017.075840 submit/tizen/20161017.013745 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.092423 submit/tizen_3.0_common/20161104.104000
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 14 Oct 2016 13:24:43 +0000 (15:24 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 14 Oct 2016 13:27:03 +0000 (15:27 +0200)
There is a requirement for fixed-size tuples:
size of such tuple must be a multiply of its required alignment.
That part was overlooked in the implementation.
This commit adds padding accounting for both reading and writing.

Change-Id: I0825be6436b93b836dc333f5a395fdf1021f2a06

dbus/dbus-marshal-gvariant.c

index ebd07fea6268661a142e1331dd02d82bdc454507..1348965e0b83d3f421ec8087c2636dd143745a06 100644 (file)
@@ -904,6 +904,10 @@ _dbus_reader_get_signature_fixed_size (const DBusString *signature, int *pos, in
       case DBUS_STRUCT_END_CHAR:
       case DBUS_DICT_ENTRY_END_CHAR:
         depth--;
+               /* For fixed-size structs we need to account padding.
+                */
+               if (!variable)
+                       res = _DBUS_ALIGN_VALUE (res, current_alignment);
         break;
       case DBUS_STRUCT_BEGIN_CHAR:
       case DBUS_DICT_ENTRY_BEGIN_CHAR:
@@ -1366,6 +1370,17 @@ _dbus_writer_unrecurse_gvariant_write (DBusTypeWriter *writer,
                                                 writer->value_pos);
       writer->value_pos += sub_len;
 
+      /* Structs may have padding if they are fixed-size structs.
+       * This is because of requirement that struct size must be a multiply
+       * of required alignment.
+       */
+      if (sub->is_fixed)
+      {
+        diff = _DBUS_ALIGN_VALUE (sub_len, sub->alignment) - sub_len;
+        result = result && _dbus_string_insert_bytes (writer->value_str, writer->value_pos, diff, 0);
+        writer->value_pos += diff;
+      }
+
       _dbus_string_free (sub->value_str);
       dbus_free (sub->value_str);