[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/19] block/qcow2-threads: fix qcow2_decompress
From: |
Max Reitz |
Subject: |
[PULL 10/19] block/qcow2-threads: fix qcow2_decompress |
Date: |
Wed, 11 Mar 2020 14:52:04 +0100 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
On success path we return what inflate() returns instead of 0. And it
most probably works for Z_STREAM_END as it is positive, but is
definitely broken for Z_BUF_ERROR.
While being here, switch to errno return code, to be closer to
qcow2_compress API (and usual expectations).
Revert condition in if to be more positive. Drop dead initialization of
ret.
Cc: address@hidden # v4.0
Fixes: 341926ab83e2b
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
Reviewed-by: Ján Tomko <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2-threads.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
index 77bb578cdf..a68126f291 100644
--- a/block/qcow2-threads.c
+++ b/block/qcow2-threads.c
@@ -128,12 +128,12 @@ static ssize_t qcow2_compress(void *dest, size_t
dest_size,
* @src - source buffer, @src_size bytes
*
* Returns: 0 on success
- * -1 on fail
+ * -EIO on fail
*/
static ssize_t qcow2_decompress(void *dest, size_t dest_size,
const void *src, size_t src_size)
{
- int ret = 0;
+ int ret;
z_stream strm;
memset(&strm, 0, sizeof(strm));
@@ -144,17 +144,19 @@ static ssize_t qcow2_decompress(void *dest, size_t
dest_size,
ret = inflateInit2(&strm, -12);
if (ret != Z_OK) {
- return -1;
+ return -EIO;
}
ret = inflate(&strm, Z_FINISH);
- if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
+ if ((ret == Z_STREAM_END || ret == Z_BUF_ERROR) && strm.avail_out == 0) {
/*
* We approve Z_BUF_ERROR because we need @dest buffer to be filled,
but
* @src buffer may be processed partly (because in qcow2 we know size
of
* compressed data with precision of one sector)
*/
- ret = -1;
+ ret = 0;
+ } else {
+ ret = -EIO;
}
inflateEnd(&strm);
--
2.24.1
- [PULL 00/19] Block patches, Max Reitz, 2020/03/11
- [PULL 01/19] luks: extract qcrypto_block_calculate_payload_offset(), Max Reitz, 2020/03/11
- [PULL 02/19] luks: implement .bdrv_measure(), Max Reitz, 2020/03/11
- [PULL 05/19] block/curl: HTTP header fields allow whitespace around values, Max Reitz, 2020/03/11
- [PULL 04/19] iotests: add 288 luks qemu-img measure test, Max Reitz, 2020/03/11
- [PULL 06/19] block/curl: HTTP header field names are case insensitive, Max Reitz, 2020/03/11
- [PULL 09/19] qemu-img: free memory before re-assign, Max Reitz, 2020/03/11
- [PULL 08/19] block/qcow2: do free crypto_opts in qcow2_close(), Max Reitz, 2020/03/11
- [PULL 03/19] qemu-img: allow qemu-img measure --object without a filename, Max Reitz, 2020/03/11
- [PULL 10/19] block/qcow2-threads: fix qcow2_decompress,
Max Reitz <=
- [PULL 07/19] iotests: Fix nonportable use of od --endian, Max Reitz, 2020/03/11
- [PULL 11/19] job: refactor progress to separate object, Max Reitz, 2020/03/11
- [PULL 12/19] block/block-copy: fix progress calculation, Max Reitz, 2020/03/11
- [PULL 13/19] block/block-copy: specialcase first copy_range request, Max Reitz, 2020/03/11
- [PULL 14/19] block/block-copy: use block_status, Max Reitz, 2020/03/11
- [PULL 15/19] block/block-copy: factor out find_conflicting_inflight_req, Max Reitz, 2020/03/11
- [PULL 16/19] block/block-copy: refactor interfaces to use bytes instead of end, Max Reitz, 2020/03/11
- [PULL 17/19] block/block-copy: rename start to offset in interfaces, Max Reitz, 2020/03/11
- [PULL 18/19] block/block-copy: reduce intersecting request lock, Max Reitz, 2020/03/11
- [PULL 19/19] block/block-copy: hide structure definitions, Max Reitz, 2020/03/11