From 546293fa85416f739f1cfc125c5c4bcd25075a5d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 7 May 2011 02:01:22 -0400 Subject: [PATCH] Add checks on packet and content size Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 08834e97..717f48d4 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -448,6 +448,21 @@ int create_stream_packet_index(struct ctf_trace *td, /* Use content size if non-zero, else file size */ packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT; } + + /* Validate content size and packet size values */ + if (packet_index.content_size > packet_index.packet_size) { + fprintf(stdout, "[error] Content size (%zu bits) is larger than packet size (%zu bits).\n", + packet_index.content_size, packet_index.packet_size); + return -EINVAL; + } + + if (packet_index.packet_size > filestats.st_size * CHAR_BIT) { + fprintf(stdout, "[error] Packet size (%zu bits) is larger than file size (%zu bits).\n", + packet_index.content_size, filestats.st_size * CHAR_BIT); + return -EINVAL; + } + + /* Save position after header and context */ packet_index.data_offset = pos->offset; -- 2.34.1