block/qcow2-threads: fix qcow2_decompress
PATCH 1/1 block/qcow2-threads: fix qcow2_decompress
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.
---
Hi!
Reviewing Den's series about zstd in qcow2 support, I found an existing bug. Let's fix it. This is to be a new base of zstd series.
block/qcow2-threads.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
block/qcow2-threads.c +7 -5
@@ -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);
Signature · 1 line
2.21.0
Quoted 7 lines · Vladimir Sementsov-Ogievskiy
On success path we return what
inflate()returns instead of 0. And it most probably works forZ_STREAM_ENDas it is positive, but is definitely broken forZ_BUF_ERROR.While being here, switch to errno return code, to be closer to
qcow2_compressAPI (and usual expectations).
Quoted 6 lines
Revert condition in if to be more positive. Drop dead initialization of ret.
Cc [email protected] # v4.0Fixes 341926ab83e2bSigned-off-by Vladimir Sementsov-Ogievskiy <[email protected]>
Berto
Quoted 15 lines · Vladimir Sementsov-Ogievskiy
On success path we return what
inflate()returns instead of 0. And it most probably works forZ_STREAM_ENDas it is positive, but is definitely broken forZ_BUF_ERROR.While being here, switch to errno return code, to be closer to
qcow2_compressAPI (and usual expectations).Revert condition in if to be more positive. Drop dead initialization of ret.
Cc [email protected] # v4.0Fixes 341926ab83e2bSigned-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Quoted 8 lines
Hi!
Reviewing Den's series about zstd in qcow2 support, I found an existing bug. Let's fix it. This is to be a new base of zstd series.
block/qcow2-threads.c| 12 +++++++-----1 file changed, 7 insertions(+), 5 deletions(-)
Jano
Max Reitz
AppliedQuoted 15 lines · Vladimir Sementsov-Ogievskiy
On success path we return what
inflate()returns instead of 0. And it most probably works forZ_STREAM_ENDas it is positive, but is definitely broken forZ_BUF_ERROR.While being here, switch to errno return code, to be closer to
qcow2_compressAPI (and usual expectations).Revert condition in if to be more positive. Drop dead initialization of ret.
Cc [email protected] # v4.0Fixes 341926ab83e2bSigned-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Quoted 7 lines
Hi!
Reviewing Den's series about zstd in qcow2 support, I found an existing bug. Let's fix it. This is to be a new base of zstd series.
block/qcow2-threads.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Thanks, applied to my block branch:
https://git.xanclic.moe/XanClic/qemu/commits/branch/block
Max