Fix: test content size vs headers len
[babeltrace.git] / formats / ctf / ctf.c
index 759708856b0a2044c4802325d2a2434ae0525287..794e428c51d069a97354826b17f0f391afbafcbf 100644 (file)
@@ -1572,6 +1572,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 +1721,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) {
@@ -1849,6 +1859,10 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
                        goto error_free;
                }
                file_stream->pos.index_fp = fdopen(ret, "r");
+               if (!file_stream->pos.index_fp) {
+                       perror("fdopen() error");
+                       goto error_free;
+               }
                ret = import_stream_packet_index(td, file_stream);
                if (ret) {
                        ret = -1;
This page took 0.022708 seconds and 4 git commands to generate.