From: Michael Tremer Date: Thu, 30 Jan 2025 11:30:21 +0000 (+0000) Subject: compress: Fix flushing Zstandard output data X-Git-Tag: 0.9.30~263 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=480ac3f94ddfec1507a20524a951f5689a873218;p=pakfire.git compress: Fix flushing Zstandard output data Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/compress.c b/src/pakfire/compress.c index 31151631..afabe206 100644 --- a/src/pakfire/compress.c +++ b/src/pakfire/compress.c @@ -473,6 +473,7 @@ static ssize_t zstd_write(void* data, const char* buffer, size_t size) { static int zstd_flush(void* data) { struct zstd_cookie* cookie = data; + ssize_t bytes_left; int r; // Fail if were given no cookie @@ -492,18 +493,20 @@ static int zstd_flush(void* data) { cookie->out.size = sizeof(cookie->buffer); cookie->out.pos = 0; - r = ZSTD_endStream(cookie->cstream, &cookie->out); - if (ZSTD_isError(r)) + bytes_left = ZSTD_endStream(cookie->cstream, &cookie->out); + if (ZSTD_isError(bytes_left)) return -1; + // Otherwise we write the buffer to the file + if (cookie->out.pos) { + r = fwrite(cookie->buffer, 1, cookie->out.pos, cookie->f); + if (r < (ssize_t)cookie->out.pos) + return -1; + } + // If the buffer is empty we are done - if (r == 0) + if (bytes_left == 0) break; - - // Otherwise we write the buffer to the file - r = fwrite(cookie->buffer, 1, cookie->out.pos, cookie->f); - if (r < (ssize_t)cookie->out.pos) - return -1; } }