[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 52/78] block/qcow2-threads: fix qcow2_decompress
From: |
Michael Roth |
Subject: |
[PATCH 52/78] block/qcow2-threads: fix qcow2_decompress |
Date: |
Tue, 16 Jun 2020 09:15:21 -0500 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
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: qemu-stable@nongnu.org # v4.0
Fixes: 341926ab83e2b
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200302150930.16218-1-vsementsov@virtuozzo.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
(cherry picked from commit e7266570f2cf7b3ca2a156c677ee0a59d563458b)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
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 8f5a0d1ebe..0d193d1614 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.17.1
- [PATCH 42/78] plugins/core: add missing break in cb_to_tcg_flags, (continued)
- [PATCH 42/78] plugins/core: add missing break in cb_to_tcg_flags, Michael Roth, 2020/06/16
- [PATCH 45/78] qcow2: Fix qcow2_alloc_cluster_abort() for external data file, Michael Roth, 2020/06/16
- [PATCH 47/78] qcow2: Fix alloc_cluster_abort() for pre-existing clusters, Michael Roth, 2020/06/16
- [PATCH 41/78] s390/sclp: improve special wait psw logic, Michael Roth, 2020/06/16
- [PATCH 48/78] iotests/026: Test EIO on preallocated zero cluster, Michael Roth, 2020/06/16
- [PATCH 04/78] qapi: better document NVMe blockdev @device parameter, Michael Roth, 2020/06/16
- [PATCH 43/78] tcg: save vaddr temp for plugin usage, Michael Roth, 2020/06/16
- [PATCH 49/78] iotests/026: Test EIO on allocation in a data-file, Michael Roth, 2020/06/16
- [PATCH 51/78] scsi/qemu-pr-helper: Fix out-of-bounds access to trnptid_list[], Michael Roth, 2020/06/16
- [PATCH 50/78] virtio: gracefully handle invalid region caches, Michael Roth, 2020/06/16
- [PATCH 52/78] block/qcow2-threads: fix qcow2_decompress,
Michael Roth <=
- [PATCH 54/78] block/block-copy: fix progress calculation, Michael Roth, 2020/06/16
- [PATCH 53/78] job: refactor progress to separate object, Michael Roth, 2020/06/16
- [PATCH 56/78] block/io: fix bdrv_co_do_copy_on_readv, Michael Roth, 2020/06/16
- [PATCH 55/78] target/ppc: Fix rlwinm on ppc64, Michael Roth, 2020/06/16
- [PATCH 57/78] compat: disable edid on correct virtio-gpu device, Michael Roth, 2020/06/16
- [PATCH 58/78] qga: Installer: Wait for installation to finish, Michael Roth, 2020/06/16
- [PATCH 59/78] qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error, Michael Roth, 2020/06/16
- [PATCH 60/78] qga-win: prevent crash when executing guest-file-read with large count, Michael Roth, 2020/06/16
- [PATCH 05/78] target/arm: ensure we use current exception state after SCR update, Michael Roth, 2020/06/16
- [PATCH 61/78] qga: Fix undefined C behavior, Michael Roth, 2020/06/16