Thrift: Align the endianness for double

Compact protocol uses little endian doubles instead of big endian like compact.
This issue is documented as an accident that became the de-facto standard.

For consistency, the sub-tvbuff_t given to delegated sub-dissectors is aligned
with binary protocol to allow a sub-dissector to work with both binary and compact.
This commit is contained in:
Triton Circonflexe 2024-02-24 21:59:30 +01:00 committed by AndersBroman
parent 4eaf10bc4e
commit 9840e6247f
1 changed files with 16 additions and 1 deletions

View File

@ -1265,7 +1265,22 @@ dissect_thrift_raw_double(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, i
thrift_opt->use_std_dissector = TRUE;
if (raw_dissector != NULL) {
tvbuff_t* sub_tvb = tvb_new_subset_length(tvb, offset, TBP_THRIFT_DOUBLE_LEN);
tvbuff_t* sub_tvb;
if (thrift_opt->tprotocol & PROTO_THRIFT_COMPACT) {
/* Create a sub-tvbuff_t in big endian format as documented. */
guint8 *data = wmem_alloc(wmem_packet_scope(), TBP_THRIFT_DOUBLE_LEN);
data[0] = tvb_get_guint8(tvb, offset + 7);
data[1] = tvb_get_guint8(tvb, offset + 6);
data[2] = tvb_get_guint8(tvb, offset + 5);
data[3] = tvb_get_guint8(tvb, offset + 4);
data[4] = tvb_get_guint8(tvb, offset + 3);
data[5] = tvb_get_guint8(tvb, offset + 2);
data[6] = tvb_get_guint8(tvb, offset + 1);
data[7] = tvb_get_guint8(tvb, offset);
sub_tvb = tvb_new_child_real_data(tvb, data, TBP_THRIFT_DOUBLE_LEN, TBP_THRIFT_DOUBLE_LEN);
} else {
sub_tvb = tvb_new_subset_length(tvb, offset, TBP_THRIFT_DOUBLE_LEN);
}
thrift_opt->use_std_dissector = FALSE;
raw_dissector(sub_tvb, pinfo, tree, thrift_opt);
}