From nobody Thu Dec 18 17:58:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583935449; cv=none; d=zohomail.com; s=zohoarc; b=b3EuNW8fgMV2fBCwd6qTeijOSQEYjrDyO2ZoPf6mGhJIuZ9+o5WO/FaMzaQvT3LzJElOFq3ST1V+IByNcUPwckETePyLUp6sSvMPPaRGEy29iLtIiZsNsWsjVk5oU30SwrMqqO2JNYQqYxi82aYx18rFcCGyvCh9zg7p+YPYlS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583935449; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tRN4EUcrPRh8eKR7KMfsL9d2OqQY+/CgfGBxmUQmmhY=; b=fGooPn18/Qve1vtikCpGcG5RHWxWLngbFIevUy+wMqmZv9/ovc72gkNT43mts1VvGXVgpSgWEQhCNOz+KesxU5+7WF58jHw1nvL/PgL826braZvHiVeMiaW34TnLERe6bjJtlyyYSd1EU3y+6ZSTI+Lyn6Yql9o9V+5UW//EpT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583935449493402.85312010181485; Wed, 11 Mar 2020 07:04:09 -0700 (PDT) Received: from localhost ([::1]:52752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC1xw-0000ty-0w for importer@patchew.org; Wed, 11 Mar 2020 10:04:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36338) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC1n2-0004Gt-Vz for qemu-devel@nongnu.org; Wed, 11 Mar 2020 09:52:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC1n0-0002eR-FQ for qemu-devel@nongnu.org; Wed, 11 Mar 2020 09:52:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32264 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jC1n0-0002dM-BP for qemu-devel@nongnu.org; Wed, 11 Mar 2020 09:52:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-LqRdiAoZO6q70Pzrladl_Q-1; Wed, 11 Mar 2020 09:52:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B616B8017CC; Wed, 11 Mar 2020 13:52:46 +0000 (UTC) Received: from localhost (ovpn-117-216.ams2.redhat.com [10.36.117.216]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5348C60C99; Wed, 11 Mar 2020 13:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583934770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRN4EUcrPRh8eKR7KMfsL9d2OqQY+/CgfGBxmUQmmhY=; b=GtmvrMKoOH5oLPQm7bKgcdr5oY6DYnCmiKB4WAOPVD6/WWTBxyVX8SP8CU9tJMj2ZvLQsK lZV7tiNVKdI6tVHqPe6GRyoNFUaRN7ckhPSeZanmKf1mn3s02fmanAniV3i6w5GdUCGE9v 6aSB5IUwdVSiFY4fN0SKBmsIuo6CeTg= X-MC-Unique: LqRdiAoZO6q70Pzrladl_Q-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 10/19] block/qcow2-threads: fix qcow2_decompress Date: Wed, 11 Mar 2020 14:52:04 +0100 Message-Id: <20200311135213.1242028-11-mreitz@redhat.com> In-Reply-To: <20200311135213.1242028-1-mreitz@redhat.com> References: <20200311135213.1242028-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy 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 Message-Id: <20200302150930.16218-1-vsementsov@virtuozzo.com> Reviewed-by: Alberto Garcia Reviewed-by: J=C3=A1n Tomko Signed-off-by: Max Reitz --- 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 =3D 0; + int ret; z_stream strm; =20 memset(&strm, 0, sizeof(strm)); @@ -144,17 +144,19 @@ static ssize_t qcow2_decompress(void *dest, size_t de= st_size, =20 ret =3D inflateInit2(&strm, -12); if (ret !=3D Z_OK) { - return -1; + return -EIO; } =20 ret =3D inflate(&strm, Z_FINISH); - if ((ret !=3D Z_STREAM_END && ret !=3D Z_BUF_ERROR) || strm.avail_out = !=3D 0) { + if ((ret =3D=3D Z_STREAM_END || ret =3D=3D Z_BUF_ERROR) && strm.avail_= out =3D=3D 0) { /* * We approve Z_BUF_ERROR because we need @dest buffer to be fille= d, but * @src buffer may be processed partly (because in qcow2 we know s= ize of * compressed data with precision of one sector) */ - ret =3D -1; + ret =3D 0; + } else { + ret =3D -EIO; } =20 inflateEnd(&strm); --=20 2.24.1