From 7801fd9e92d354fa123aef74c7751c4b53dc17dc Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 12 Mar 2019 16:17:11 -0400 Subject: [PATCH] Fix: set effective byte order of FT copy _and_ original In bt_ctf_trace_add_stream_class() and bt_ctf_stream_class_add_event_class(), it is possible that field types are copied for length/tag field type resolving purposes (we cannot keep the same sequence field type reference at different locations within the metadata tree because then the resolved length field type would be the same reference). However, the effective byte order is set on the copied field types. If the user keeps an original field type reference, then its byte order remains unset and the user can still create a field from this field type. This means that the field serialization function reads a wrong effective byte order, possibly leading to a corrupted stream file. This patch makes bt_ctf_trace_add_stream_class() and bt_ctf_stream_class_add_event_class() set the effective byte order of the original field types too. Signed-off-by: Philippe Proulx --- formats/ctf/ir/stream-class.c | 14 ++++++++++++++ formats/ctf/ir/trace.c | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index c5b1b15ff..36ea4dad1 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -431,6 +431,20 @@ int bt_ctf_stream_class_add_event_class( bt_object_set_parent(event_class, stream_class); if (trace) { + if (stream_class->byte_order) { + /* + * Set the effective byte order of all the event + * class's field type now as we are about to + * maybe replace some field types (with + * bt_ctf_validation_replace_types()). This + * allows the user to use the original field + * type to create a field and still have the + * correct effective byte order. + */ + bt_ctf_event_class_set_native_byte_order(event_class, + stream_class->byte_order); + } + /* * At this point we know that the function will be * successful. Therefore we can replace the event diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index a84279d2a..e1c9a7e0c 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -591,6 +591,15 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, bt_object_set_parent(stream_class, trace); g_ptr_array_add(trace->stream_classes, stream_class); + /* + * Set the effective byte order of all the stream class's field + * type now as we are about to maybe replace some field types + * (with bt_ctf_validation_replace_types()). This allows the + * user to use the original field type to create a field and + * still have the correct effective byte order. + */ + bt_ctf_stream_class_set_byte_order(stream_class, trace->byte_order); + /* * At this point we know that the function will be successful. * Therefore we can replace the trace and stream class field