From 7e18eedf5333dbd6f1e0a8d873a7275dee1ed396 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Mon, 13 Feb 2012 08:33:58 -0500 Subject: [PATCH] Use 64-bit type for packet and content size Expression filestats.st_size * CHAR_BIT wraps around very easily when stored to 32-bit size_t. Currently BabelTrace cannot handle input larger than 256Mb because of this and diagnostic messages from this function can be incorrect because of overflow. This patch fixes my immediate problem, but further work is needed for proper large file support i.e. handling files bigger than 2Gb. Signed-off-by: Juha Niskanen Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 8 ++++---- include/babeltrace/ctf/types.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 3ce428c3..ea760f0e 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -1185,14 +1185,14 @@ int create_stream_packet_index(struct ctf_trace *td, /* Validate content size and packet size values */ if (packet_index.content_size > packet_index.packet_size) { - fprintf(stderr, "[error] Content size (%zu bits) is larger than packet size (%zu bits).\n", + fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n", packet_index.content_size, packet_index.packet_size); return -EINVAL; } - if (packet_index.packet_size > (filestats.st_size - packet_index.offset) * CHAR_BIT) { - fprintf(stderr, "[error] Packet size (%zu bits) is larger than remaining file size (%zu bits).\n", - packet_index.content_size, (size_t) (filestats.st_size - packet_index.offset) * CHAR_BIT); + if (packet_index.packet_size > ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT) { + fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n", + packet_index.content_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT); return -EINVAL; } diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 12cca6e1..9cbb3387 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -36,8 +36,8 @@ struct bt_stream_callbacks; struct packet_index { off_t offset; /* offset of the packet in the file, in bytes */ off_t data_offset; /* offset of data within the packet, in bits */ - size_t packet_size; /* packet size, in bits */ - size_t content_size; /* content size, in bits */ + uint64_t packet_size; /* packet size, in bits */ + uint64_t content_size; /* content size, in bits */ uint64_t timestamp_begin; uint64_t timestamp_end; uint32_t events_discarded; -- 2.34.1