Handle packets containing only a header
[babeltrace.git] / formats / ctf / ctf.c
index 317457e883c5d7dab6271d3b5c430281e96ca987..5cf8097ce709892580c49957cf4751f9bc2e753b 100644 (file)
@@ -471,6 +471,15 @@ int ctf_read_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *str
         */
        if (unlikely(pos->offset == EOF))
                return EOF;
+
+       if (pos->content_size == 0) {
+               /* Stream is inactive for now (live reading). */
+               return EAGAIN;
+       }
+       /* Packet only contains headers */
+       if (pos->offset == pos->content_size)
+               return EAGAIN;
+
        assert(pos->offset < pos->content_size);
 
        /* Read event header */
@@ -1572,6 +1581,11 @@ begin:
                return -EINVAL;
        }
 
+       if (packet_index.content_size < pos->offset) {
+               fprintf(stderr, "[error] Invalid CTF stream: content size is smaller than packet headers.\n");
+               return -EINVAL;
+       }
+
        if ((packet_index.packet_size >> LOG2_CHAR_BIT) == 0) {
                fprintf(stderr, "[error] Invalid CTF stream: packet size needs to be at least one byte\n");
                return -EINVAL;
@@ -1716,6 +1730,11 @@ int import_stream_packet_index(struct ctf_trace *td,
                ret = -1;
                goto error;
        }
+       if (index_hdr.packet_index_len == 0) {
+               fprintf(stderr, "[error] Packet index length cannot be 0.\n");
+               ret = -1;
+               goto error;
+       }
 
        while ((index_read = fread(&ctf_index, index_hdr.packet_index_len, 1,
                                        pos->index_fp)) == 1) {
This page took 0.026702 seconds and 4 git commands to generate.