From 3dd513bb4187aa06c6a0e773a00efd5e44bbd82b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 27 Nov 2013 03:38:23 -0500 Subject: [PATCH] Fix: reversed logic in packet vs content size As described in CTF section 5.2 "If the packet size field is missing, the whole stream only contains a single packet. If the content size field is missing, the packet is filled (no padding). The content and packet sizes include all headers." Here is the correct semantic: * Content size and packet size are available: Packet is filled with data up to content size, and then with padding up to packet size. * Content size available, no packet size field: The stream has a single packet. It is filled up to content size, and the rest is padding. * Packet size available, no content size field: Packet filled completely, no padding. Fixes #683 Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index db6615b4..687e360e 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -1486,28 +1486,28 @@ begin: fprintf(stderr, "[error] Unable to read packet context: %s\n", strerror(-ret)); return ret; } - /* read content size from header */ - len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size")); + /* read packet size from header */ + len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size")); if (len_index >= 0) { struct bt_definition *field; field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index); - packet_index.content_size = bt_get_unsigned_int(field); + packet_index.packet_size = bt_get_unsigned_int(field); } else { /* Use file size for packet size */ - packet_index.content_size = filesize * CHAR_BIT; + packet_index.packet_size = filesize * CHAR_BIT; } - /* read packet size from header */ - len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size")); + /* read content size from header */ + len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size")); if (len_index >= 0) { struct bt_definition *field; field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index); - packet_index.packet_size = bt_get_unsigned_int(field); + packet_index.content_size = bt_get_unsigned_int(field); } else { - /* Use content size if non-zero, else file size */ - packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT; + /* Use packet size if non-zero, else file size */ + packet_index.content_size = packet_index.packet_size ? : filesize * CHAR_BIT; } /* read timestamp begin from header */ -- 2.34.1