From nobody Fri Nov 7 03:51:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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=listsout.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=gmail.com Return-Path: Received: from listsout.gnu.org (listsout.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154651627706954.75090057003024; Thu, 3 Jan 2019 03:51:17 -0800 (PST) Received: from localhost ([127.0.0.1]:52817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf1Wt-0003s6-Ua for importer@patchew.org; Thu, 03 Jan 2019 06:51:15 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf1TW-0000i2-A9 for qemu-devel@nongnu.org; Thu, 03 Jan 2019 06:47:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf1TU-0003XS-Rj for qemu-devel@nongnu.org; Thu, 03 Jan 2019 06:47:46 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:41212) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf1TU-0003X2-MB; Thu, 03 Jan 2019 06:47:44 -0500 Received: by mail-pg1-x542.google.com with SMTP id m1so15924711pgq.8; Thu, 03 Jan 2019 03:47:44 -0800 (PST) Received: from localhost.localdomain (223-137-100-47.emome-ip.hinet.net. [223.137.100.47]) by smtp.gmail.com with ESMTPSA id t67sm103011808pfd.90.2019.01.03.03.47.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 03:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ECjJODVG7RHE2yh+0zGzQM26frs1LXFHcmZRJ3Nk260=; b=H5gM42NSnSJKbyVY9W9No+/jgS3KFaMKr2/I3IYkiTjpYBhR+fmh6S2as2v5m1ttjZ 4OIX1xGuqHaat4VNOrb20yp3JUzpT8ZnttYCKZqo1gtSeUSEkR37t4To9mZ9M0e7blzp 8+p4QyeodwMN7S16/w1q6rSqrlDqQoYLjjrXdqnfliWjl5eCk+cnELXOwbCW8ypAvx2b 016L0I3lPJPcLRz07WUaZ6T4ZysLPBLyz7ZctvjtwwDN8HSoKmQBZiJS5ogYg4AG6BxW utMSA/95NC8QplULUR0iHBiJK9wpsc2B3WiQF8VWmlUgKlNju/AtY8uyAkKj2oFA3hM7 3auw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ECjJODVG7RHE2yh+0zGzQM26frs1LXFHcmZRJ3Nk260=; b=dkbU9EXqIey6MtP1ryS40xI+YzaoYlP8Uko3ZmofhUHPSZvjhn4oPr3u5NccFTsHsa IbEfcnt9yW63LzoqZ8xKUPu19nUo5MWaN7VXmQN2m3K7+uZWqUG3fgAFC9igzwb7mwUk jNU8xnMJ+ecS4gKClwnDHqtIbdy8/vVoV8cWIsyJ21Pixf268entyMDFjXAcp6/81+4x fXcPg5dw9Vqav6iT0zMvg2fi/bTnn8k8/gLCaSV3XA9Rs1w8yCs+wxZLmIybSfqXbI04 a8mfvbyWIstavxbS3+90H9YJba0k2M4AUOpmtVdW5Xk5mR5BiKCk7T0C5mv0Gxqqo+Om 9z3w== X-Gm-Message-State: AJcUukcO9nb3hmHwzolZmbY4iz6FS/lkGrgdu69sRw1tXFPV6XWKAEyF 23VcsNPgMHAU1TG2QdprYzx4uqkWxHc= X-Google-Smtp-Source: ALg8bN4fL+1NIjkvappk5z+Sj4Ir2n6s7/1+c6dVQc++GjHoKCficcF1zaq2PdZMUwkiu7qRz9+mAg== X-Received: by 2002:a63:3602:: with SMTP id d2mr16453433pga.404.1546516063421; Thu, 03 Jan 2019 03:47:43 -0800 (PST) From: yuchenlin To: qemu-devel@nongnu.org Date: Thu, 3 Jan 2019 19:47:00 +0800 Message-Id: <20190103114700.9686-4-npes87184@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190103114700.9686-1-npes87184@gmail.com> References: <20190103114700.9686-1-npes87184@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v3 3/3] dmg: don't skip zero chunk X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yuchenlin , qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The dmg file has many tables which describe: "start from sector XXX to sector XXX, the compression method is XXX and where the compressed data resides on". Each sector in the expanded file should be covered by a table. The table will describe the offset of compressed data (or raw depends on the type) in the dmg. For example: [-----------The expanded file------------] [---bzip table ---]/* zeros */[---zlib---] ^ | if we want to read this sector. we will find bzip table which contains this sector, and get the compressed data offset, read it from dmg, uncompress it, finally write to expanded file. If we skip zero chunk (table), some sector cannot find the table which will cause search_chunk() return s->n_chunks, dmg_read_chunk() return -1 and finally causing dmg_co_preadv() return EIO. See: [-----------The expanded file------------] [---bzip table ---]/* zeros */[---zlib---] ^ | if we want to read this sector. Oops, we cannot find the table contains it... In the original implementation, we don't have zero table. When we try to read sector inside the zero chunk. We will get EIO, and skip reading. After this patch, we treat zero chunk the same as ignore chunk, it will directly write zero and avoid some sector may not find the table. After this patch: [-----------The expanded file------------] [---bzip table ---][--zeros--][---zlib---] Signed-off-by: yuchenlin Reviewed-by: Julio Faracco Reviewed-by: Stefan Hajnoczi --- block/dmg.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 9758482131..351f2991a7 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -130,7 +130,8 @@ static void update_max_chunk_size(BDRVDMGState *s, uint= 32_t chunk, case UDRW: /* copy */ uncompressed_sectors =3D DIV_ROUND_UP(s->lengths[chunk], 512); break; - case UDIG: /* zero */ + case UDZE: /* zero */ + case UDIG: /* ignore */ /* as the all-zeroes block may be large, it is treated specially: = the * sector is not copied from a large buffer, a simple memset is us= ed * instead. Therefore uncompressed_sectors does not need to be set= . */ @@ -199,8 +200,9 @@ typedef struct DmgHeaderState { static bool dmg_is_known_block_type(uint32_t entry_type) { switch (entry_type) { + case UDZE: /* zeros */ case UDRW: /* uncompressed */ - case UDIG: /* zeroes */ + case UDIG: /* ignore */ case UDZO: /* zlib */ return true; case UDBZ: /* bzip2 */ @@ -265,9 +267,10 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHea= derState *ds, /* sector count */ s->sectorcounts[i] =3D buff_read_uint64(buffer, offset + 0x10); =20 - /* all-zeroes sector (type 2) does not need to be "uncompressed" a= nd can - * therefore be unbounded. */ - if (s->types[i] !=3D UDIG && s->sectorcounts[i] > DMG_SECTORCOUNTS= _MAX) { + /* all-zeroes sector (type UDZE and UDIG) does not need to be + * "uncompressed" and can therefore be unbounded. */ + if (s->types[i] !=3D UDZE && s->types[i] !=3D UDIG + && s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) { error_report("sector count %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX); @@ -675,7 +678,8 @@ static inline int dmg_read_chunk(BlockDriverState *bs, = uint64_t sector_num) return -1; } break; - case UDIG: /* zero */ + case UDZE: /* zeros */ + case UDIG: /* ignore */ /* see dmg_read, it is treated specially. No buffer needs to be * pre-filled, the zeroes can be set directly. */ break; @@ -710,7 +714,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, ui= nt64_t bytes, /* Special case: current chunk is all zeroes. Do not perform a mem= cpy as * s->uncompressed_chunk may be too small to cover the large all-z= eroes * section. dmg_read_chunk is called to find s->current_chunk */ - if (s->types[s->current_chunk] =3D=3D UDIG) { /* all zeroes block = entry */ + if (s->types[s->current_chunk] =3D=3D UDZE + || s->types[s->current_chunk] =3D=3D UDIG) { /* all zeroes blo= ck entry */ qemu_iovec_memset(qiov, i * 512, 0, 512); continue; } --=20 2.17.1