aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2023-05-31 05:54:01 -0400
committerSteven Rostedt (Google) <rostedt@goodmis.org>2023-06-02 04:44:42 -0400
commit4b9213298599e91682129294cd317ec780785947 (patch)
treef47291475d9e806de681b491030ef5c53f1666b7
parentf30abfd2110cc1c26ed49a9c6061e76ca2646522 (diff)
downloadtrace-cmd-4b9213298599e91682129294cd317ec780785947.tar.gz
libtracecmd: Fix tracecmd_compress_copy_from() write size return
The amount written to the file returned by tracecmd_compress_copy_from() is off by 4 bytes. This is because it did not account for the writing of the number of chunks saved. Instead of calculating the amount written to the file, as lseek() is used to find the chunk value and also put it back to the end of what was written, use the results of lseek() to figure out the amount written. It appears that the decompression of the sections did not use the size of the buffer section, but instead used the size inside each chunk. That is, it read the chunks within the buffer section and based what it would read from the file by the size of each chunk, and did not use the value defined in the section header. Link: https://lore.kernel.org/linux-trace-devel/20230531055401.1f04a9fd@rorschach.local.home Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com> Reported-by: Douglas Raillard <douglas.raillard@arm.com> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217367 Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--lib/trace-cmd/trace-compress.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index 1b852f18..ca6e03b8 100644
--- a/lib/trace-cmd/trace-compress.c
+++ b/lib/trace-cmd/trace-compress.c
@@ -671,13 +671,13 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
{
unsigned int rchunk = 0;
unsigned int chunks = 0;
- unsigned int wsize = 0;
unsigned int rsize = 0;
unsigned int rmax = 0;
unsigned int csize;
unsigned int size;
unsigned int all;
unsigned int r;
+ off_t end_offset;
off_t offset;
char *buf_from;
char *buf_to;
@@ -748,8 +748,6 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
ret = write_fd(handle->fd, buf_to, size);
if (ret != size)
break;
- /* data + compress header */
- wsize += (size + 8);
chunks++;
}
} while (all > 0);
@@ -766,13 +764,14 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
endian4 = tep_read_number(handle->tep, &chunks, 4);
/* write chunks count*/
write_fd(handle->fd, &chunks, 4);
- if (lseek(handle->fd, 0, SEEK_END) == (off_t)-1)
+ end_offset = lseek(handle->fd, 0, SEEK_END);
+ if (end_offset == (off_t)-1)
return -1;
if (read_size)
*read_size = rsize;
if (write_size)
- *write_size = wsize;
+ *write_size = end_offset - offset;
return 0;
}