From 9a90484d6c7e23ce709e5e34eec2aec62b6d4cbc Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 6 Oct 2021 17:36:26 +0200 Subject: [PATCH] formats: disallow seeking in dynamic memory buffers Seeking in a dynamic memory buffer stream as provided by open_memstream() truncates the memory buffer. Seeking back to the start of the file to write a header will leave the user with just the header then. --- src/formats.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/formats.c b/src/formats.c index 3fcf4382..45ca79ca 100644 --- a/src/formats.c +++ b/src/formats.c @@ -932,7 +932,8 @@ static sox_format_t * open_write( lsx_fail("Can't set write buffer"); goto error; } - ft->seekable = is_seekable(ft); + /* Do not allow seeking in dynamic memory buffers as that would truncate the buffer. */ + ft->seekable = (buffer_ptr && !buffer) ? sox_false : is_seekable(ft); } ft->filetype = lsx_strdup(filetype); -- 2.25.1