From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571253998; cv=none; d=zoho.com; s=zohoarc; b=b+1Qk4usmoxhKeDsHZm9P/nKnRLmKyjffDyW2YvZCJaMn/oD0uuXc52/L3Ntnqd2x7pv9s6OPJGO+pwKiGRPCbcZt0OAlBM59uA8+DOlHsAuqU3BMjR7QOQaLfZOLFLwdu0KQNM8elIEGTI7lCIznTaDNsgvG27cEHv1O4yrtO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571253998; h=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=II20aN+MZFQ9TBvEaBNMfXZ1f/0dq19mcNVFYhGsAc4=; b=Qk31uAzMP4C9x1Eqdp63IXwL4rMUe7Y0JlKN3V7TqAya9tVzWDCsPvtHkHPeCqgtBNQUXjbEa532RjuaYAj5c2QsDQAlGDFXfWmNQ4OtthwMfT1sKEGFxlpS07cwUOxxX2K7Ak0IlCvg/Q/aqWRlPI0pyF1FsnX1SNuW0dH5DPw= ARC-Authentication-Results: i=1; mx.zoho.com; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571253998249659.0516853281902; Wed, 16 Oct 2019 12:26:38 -0700 (PDT) Received: from localhost ([::1]:47416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKowI-00039V-7A for importer@patchew.org; Wed, 16 Oct 2019 15:26:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32918) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoug-0001Fo-J9 for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKoue-0002Lx-Jl for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41818) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKouZ-0002GC-7r; Wed, 16 Oct 2019 15:24:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1608481F0C; Wed, 16 Oct 2019 19:24:39 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FE9060127; Wed, 16 Oct 2019 19:24:36 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 01/10] image-fuzzer: Open image files in binary mode Date: Wed, 16 Oct 2019 16:24:21 -0300 Message-Id: <20191016192430.25098-2-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 16 Oct 2019 19:24:39 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This probably never caused problems because on Linux there's no actual newline conversion happening, but on Python 3 the binary/text distinction is stronger and we must explicitly open the image file in binary mode. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/image-fuzzer/qcow2/layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index 675877da96..c57418fa15 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -503,7 +503,7 @@ class Image(object): =20 def write(self, filename): """Write an entire image to the file.""" - image_file =3D open(filename, 'w') + image_file =3D open(filename, 'wb') for field in self: image_file.seek(field.offset) image_file.write(struct.pack(field.fmt, field.value)) --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571253997; cv=none; d=zoho.com; s=zohoarc; b=Zgc6scui1/P6/Oyi7k2ZRud/7ZrPhzLcEj+8EOUjkXot5KOKd8NgrDhwmAo34sWoftWQAAtKbiEKad+lvzTii7PP92ijb9BakG/cj/YgaXNTHvtdstevnLuPKJEoZTfLaBAB9TVXkRxsb9QnhPaAafYwljouZlrKWA14GxMDYTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571253997; h=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=5KiGi7fToYCaxn60iGn3mmcQmSYJLGPJAST+OwLgXsM=; b=kbu1YcjGz9StAuEh3XVQPbFltgKkXY+zn1wvQiSTevS5OKpqLkv2SyIPjq4W1XEU9a7HZHqxEg575gEdAQC70AzU97hQtZlRq5/+qKXPxvZlUoiQ4X3LPACnTRx6GMxTx2Y2YruwZBc6wvvTz3phkcFS6qDwkVV9JxaS+XqT3Io= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571253997415505.78632679228906; Wed, 16 Oct 2019 12:26:37 -0700 (PDT) Received: from localhost ([::1]:47418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKowK-0003Dq-Gf for importer@patchew.org; Wed, 16 Oct 2019 15:26:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32936) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoui-0001GR-Jp for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKoug-0002Mv-JN for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54324) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKoua-0002Ix-Nd; Wed, 16 Oct 2019 15:24:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EAA918C890A; Wed, 16 Oct 2019 19:24:43 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6FA319C6A; Wed, 16 Oct 2019 19:24:40 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 02/10] image-fuzzer: Write bytes instead of string to image file Date: Wed, 16 Oct 2019 16:24:22 -0300 Message-Id: <20191016192430.25098-3-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Wed, 16 Oct 2019 19:24:43 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is necessary for Python 3 compatibility. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/image-fuzzer/qcow2/layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index c57418fa15..fe273d4143 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -518,7 +518,7 @@ class Image(object): rounded =3D (size + self.cluster_size - 1) & ~(self.cluster_size -= 1) if rounded > size: image_file.seek(rounded - 1) - image_file.write("\0") + image_file.write(b'\x00') image_file.close() =20 @staticmethod --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254103; cv=none; d=zoho.com; s=zohoarc; b=P/wvCyaJK94drv83Vou9nsXWJ+C/OiVu41EfhqipjvguEl+Afes/GZsIWPKimVxFpkcXp7hRSPLJMikH1XnL7vnHFKWzcPLLyGhCRICoqdy7pQ9kyzhLebZR2rqgJHn0y6KnSnwYBb7w0/sgmX5NiLJdFS4yYC/S2DO8OCegFD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254103; h=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=qdiIb8J9EtCKsvYDS6sliIqIX6pWyosmP6tKHeHKlkU=; b=NRQWg8TAskRIAHfLQbH6JaChdyWV2J3P2wAzOBRORb+LRiFXnYRWZtec1dmIv73ssYQ2E8+mprJDUS9zrSZ9oSYkDQ7N1b/FKOqCqZqakZiehyU5YShFHSzZrVXR24/Nk1zWlFj8lGVwA3fti54trg+kfTsj6DEG6nct7gVXTos= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571254103744421.95053256181154; Wed, 16 Oct 2019 12:28:23 -0700 (PDT) Received: from localhost ([::1]:47436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoy6-0005ju-Dx for importer@patchew.org; Wed, 16 Oct 2019 15:28:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32973) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoum-0001Mn-3A for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKouk-0002PS-Ak for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKoue-0002Lg-Js; Wed, 16 Oct 2019 15:24:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBE8889F302; Wed, 16 Oct 2019 19:24:47 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1567F60852; Wed, 16 Oct 2019 19:24:44 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 03/10] image-fuzzer: Explicitly use integer division operator Date: Wed, 16 Oct 2019 16:24:23 -0300 Message-Id: <20191016192430.25098-4-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Wed, 16 Oct 2019 19:24:47 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Most of the division expressions in image-fuzzer assume integer division. Use the // operator to keep the same behavior when we move to Python 3. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/qcow2/fuzz.py | 12 ++++----- tests/image-fuzzer/qcow2/layout.py | 40 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fu= zz.py index abc4f0635d..154dc06cc0 100644 --- a/tests/image-fuzzer/qcow2/fuzz.py +++ b/tests/image-fuzzer/qcow2/fuzz.py @@ -27,14 +27,14 @@ UINT64 =3D 0xffffffffffffffff UINT32_M =3D 31 UINT64_M =3D 63 # Fuzz vectors -UINT8_V =3D [0, 0x10, UINT8/4, UINT8/2 - 1, UINT8/2, UINT8/2 + 1, UINT8 - = 1, +UINT8_V =3D [0, 0x10, UINT8//4, UINT8//2 - 1, UINT8//2, UINT8//2 + 1, UINT= 8 - 1, UINT8] -UINT16_V =3D [0, 0x100, 0x1000, UINT16/4, UINT16/2 - 1, UINT16/2, UINT16/2= + 1, +UINT16_V =3D [0, 0x100, 0x1000, UINT16//4, UINT16//2 - 1, UINT16//2, UINT1= 6//2 + 1, UINT16 - 1, UINT16] -UINT32_V =3D [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32/4, UINT32/2 - 1, - UINT32/2, UINT32/2 + 1, UINT32 - 1, UINT32] -UINT64_V =3D UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64/4, - UINT64/2 - 1, UINT64/2, UINT64/2 + 1, UINT64 - 1, +UINT32_V =3D [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32//4, UINT32//2 - = 1, + UINT32//2, UINT32//2 + 1, UINT32 - 1, UINT32] +UINT64_V =3D UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4, + UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1, UINT64] STRING_V =3D ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x', '%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%2= 0n', diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index fe273d4143..6501c9fd4b 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -253,7 +253,7 @@ class Image(object): ['>I', self.ext_offset, 0x6803f857, 'ext_magic'], # One feature table contains 3 fields and takes 48 bytes ['>I', self.ext_offset + UINT32_S, - len(feature_tables) / 3 * 48, 'ext_length'] + len(feature_tables) // 3 * 48, 'ext_length'] ] + feature_tables) self.ext_offset =3D inner_offset =20 @@ -271,7 +271,7 @@ class Image(object): def create_l2_entry(host, guest, l2_cluster): """Generate one L2 entry.""" offset =3D l2_cluster * self.cluster_size - l2_size =3D self.cluster_size / UINT64_S + l2_size =3D self.cluster_size // UINT64_S entry_offset =3D offset + UINT64_S * (guest % l2_size) cluster_descriptor =3D host * self.cluster_size if not self.header['version'][0].value =3D=3D 2: @@ -283,8 +283,8 @@ class Image(object): =20 def create_l1_entry(l2_cluster, l1_offset, guest): """Generate one L1 entry.""" - l2_size =3D self.cluster_size / UINT64_S - entry_offset =3D l1_offset + UINT64_S * (guest / l2_size) + l2_size =3D self.cluster_size // UINT64_S + entry_offset =3D l1_offset + UINT64_S * (guest // l2_size) # While snapshots are not supported bit #63 =3D 1 entry_val =3D (1 << 63) + l2_cluster * self.cluster_size return ['>Q', entry_offset, entry_val, 'l1_entry'] @@ -298,11 +298,11 @@ class Image(object): l2 =3D [] else: meta_data =3D self._get_metadata() - guest_clusters =3D random.sample(range(self.image_size / + guest_clusters =3D random.sample(range(self.image_size // self.cluster_size), len(self.data_clusters)) # Number of entries in a L1/L2 table - l_size =3D self.cluster_size / UINT64_S + l_size =3D self.cluster_size // UINT64_S # Number of clusters necessary for L1 table l1_size =3D int(ceil((max(guest_clusters) + 1) / float(l_size*= *2))) l1_start =3D self._get_adjacent_clusters(self.data_clusters | @@ -318,7 +318,7 @@ class Image(object): # L2 entries l2 =3D [] for host, guest in zip(self.data_clusters, guest_clusters): - l2_id =3D guest / l_size + l2_id =3D guest // l_size if l2_id not in l2_ids: l2_ids.append(l2_id) l2_clusters.append(self._get_adjacent_clusters( @@ -339,14 +339,14 @@ class Image(object): def allocate_rfc_blocks(data, size): """Return indices of clusters allocated for refcount blocks.""" cluster_ids =3D set() - diff =3D block_ids =3D set([x / size for x in data]) + diff =3D block_ids =3D set([x // size for x in data]) while len(diff) !=3D 0: # Allocate all yet not allocated clusters new =3D self._get_available_clusters(data | cluster_ids, len(diff)) # Indices of new refcount blocks necessary to cover cluste= rs # in 'new' - diff =3D set([x / size for x in new]) - block_ids + diff =3D set([x // size for x in new]) - block_ids cluster_ids |=3D new block_ids |=3D diff return cluster_ids, block_ids @@ -359,7 +359,7 @@ class Image(object): blocks =3D set(init_blocks) clusters =3D set() # Number of entries in one cluster of the refcount table - size =3D self.cluster_size / UINT64_S + size =3D self.cluster_size // UINT64_S # Number of clusters necessary for the refcount table based on # the current number of refcount blocks table_size =3D int(ceil((max(blocks) + 1) / float(size))) @@ -373,7 +373,7 @@ class Image(object): table_size + 1)) # New refcount blocks necessary for clusters occupied by the # refcount table - diff =3D set([c / block_size for c in table_clusters]) - blocks + diff =3D set([c // block_size for c in table_clusters]) - bloc= ks blocks |=3D diff while len(diff) !=3D 0: # Allocate clusters for new refcount blocks @@ -382,12 +382,12 @@ class Image(object): len(diff)) # Indices of new refcount blocks necessary to cover # clusters in 'new' - diff =3D set([x / block_size for x in new]) - blocks + diff =3D set([x // block_size for x in new]) - blocks clusters |=3D new blocks |=3D diff # Check if the refcount table needs one more cluster if int(ceil((max(blocks) + 1) / float(size))) > table_size: - new_block_id =3D (table_start + table_size) / block_si= ze + new_block_id =3D (table_start + table_size) // block_s= ize # Check if the additional table cluster needs # one more refcount block if new_block_id not in blocks: @@ -399,13 +399,13 @@ class Image(object): def create_table_entry(table_offset, block_cluster, block_size, cluster): """Generate a refcount table entry.""" - offset =3D table_offset + UINT64_S * (cluster / block_size) + offset =3D table_offset + UINT64_S * (cluster // block_size) return ['>Q', offset, block_cluster * self.cluster_size, 'refcount_table_entry'] =20 def create_block_entry(block_cluster, block_size, cluster): """Generate a list of entries for the current block.""" - entry_size =3D self.cluster_size / block_size + entry_size =3D self.cluster_size // block_size offset =3D block_cluster * self.cluster_size entry_offset =3D offset + entry_size * (cluster % block_size) # While snapshots are not supported all refcounts are set to 1 @@ -415,7 +415,7 @@ class Image(object): # Number of refcount entries per refcount block # Convert self.cluster_size from bytes to bits to have the same # base for the numerator and denominator - block_size =3D self.cluster_size * 8 / refcount_bits + block_size =3D self.cluster_size * 8 // refcount_bits meta_data =3D self._get_metadata() if len(self.data_clusters) =3D=3D 0: # All metadata for an empty guest image needs 4 clusters: @@ -452,8 +452,8 @@ class Image(object): rfc_blocks =3D [] =20 for cluster in sorted(self.data_clusters | meta_data): - if cluster / block_size !=3D block_id: - block_id =3D cluster / block_size + if cluster // block_size !=3D block_id: + block_id =3D cluster // block_size block_cluster =3D block_clusters[block_ids.index(block_id)] rfc_table.append(create_table_entry(table_offset, block_cluster, @@ -587,7 +587,7 @@ class Image(object): def _alloc_data(img_size, cluster_size): """Return a set of random indices of clusters allocated for guest = data. """ - num_of_cls =3D img_size/cluster_size + num_of_cls =3D img_size // cluster_size return set(random.sample(range(1, num_of_cls + 1), random.randint(0, num_of_cls))) =20 @@ -595,7 +595,7 @@ class Image(object): """Return indices of clusters allocated for image metadata.""" ids =3D set() for x in self: - ids.add(x.offset/self.cluster_size) + ids.add(x.offset // self.cluster_size) return ids =20 =20 --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254280; cv=none; d=zoho.com; s=zohoarc; b=K+SZm5JWsKMoBvGTulJ53BUEpkmDqdhud4fObBrGBb0Ernnz0y6+Jh0oHX1Ovxe5gMS9DO+AttIOXlZkZ9cmMXvP25+3jf4U0whoJ2k27uyDLjNcPEFu4GrmEElxwSvjQxFmEyEYlRgaRV/F6gAQBB7sOvBXgJy+b8JsV3L8QDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254280; h=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=Q3bhk6DrqqtZH2eTyBeVlbGNNLWIm7ByDbxHidLIt7E=; b=e7DdG2bXylVSzPWILx7Ov5N5Idvf9xaGijtxxXmUYDpU7Ge036ztF3nMx0ges548KtkKZM97iH0/vXPWGtNhM+6cDP5h1S/wDnLBXfLCYzNvAv3XHnHSENkUJtuqAdDeyRO3GeEOT6ULwbCLGo1tjk8ziADY9c/e5IRFZ+Ll/w4= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571254280865205.6563909406259; Wed, 16 Oct 2019 12:31:20 -0700 (PDT) Received: from localhost ([::1]:47458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKp0x-0007qM-QX for importer@patchew.org; Wed, 16 Oct 2019 15:31:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33007) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoup-0001S3-5d for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKoun-0002Rf-Ur for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:24:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38570) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKoul-0002Pa-4V; Wed, 16 Oct 2019 15:24:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FF0B30860BE; Wed, 16 Oct 2019 19:24:54 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8021C5D9DC; Wed, 16 Oct 2019 19:24:49 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 04/10] image-fuzzer: Use io.StringIO Date: Wed, 16 Oct 2019 16:24:24 -0300 Message-Id: <20191016192430.25098-5-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 16 Oct 2019 19:24:54 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" StringIO.StringIO is not available on Python 3, but io.StringIO is available on both Python 2 and 3. io.StringIO is slightly different from the Python 2 StringIO module, though, so we need bytes coming from subprocess.Popen() to be explicitly decoded. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/runner.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index 95d84f38f3..94cab5bd93 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -28,7 +28,7 @@ import shutil from itertools import count import time import getopt -import StringIO +import io import resource =20 try: @@ -84,8 +84,12 @@ def run_app(fd, q_args): try: out, err =3D process.communicate() signal.alarm(0) - fd.write(out) - fd.write(err) + # fd is a text file, so we need to decode the process output before + # writing to it. + # We could be simply using the `errors` parameter of subprocess.Po= pen(), + # but this will be possible only after migrating to Python 3 + fd.write(out.decode(errors=3D'replace')) + fd.write(err.decode(errors=3D'replace')) fd.flush() return process.returncode =20 @@ -183,7 +187,7 @@ class TestEnv(object): MAX_BACKING_FILE_SIZE) * (1 << = 20) cmd =3D self.qemu_img + ['create', '-f', backing_file_fmt, backing_file_name, str(backing_file_size)] - temp_log =3D StringIO.StringIO() + temp_log =3D io.StringIO() retcode =3D run_app(temp_log, cmd) if retcode =3D=3D 0: temp_log.close() @@ -240,7 +244,7 @@ class TestEnv(object): "Backing file: %s\n" \ % (self.seed, " ".join(current_cmd), self.current_dir, backing_file_name) - temp_log =3D StringIO.StringIO() + temp_log =3D io.StringIO() try: retcode =3D run_app(temp_log, current_cmd) except OSError as e: --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254367; cv=none; d=zoho.com; s=zohoarc; b=gg1Qk1pMDrFLKMbc91rJ1EM7wk5pCTgNNWVGYYzdS8zgv0CjN265tN10oGIKobTyQAfwsdvI8MOtG7+EKMRGvKzLuQyyd0FydA7Zqp4BRZNcx5UPNPKRnaLm968Y0x6NGMt/Jxy5rT8G0wgJ00stBgq01yMEgWtcwtya+9JjUk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254367; h=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=yLwgkLlvN/XWPr5fE9jwJlABmnoCu0lS6zXyS6E99l4=; b=XqADG4bBjMFiGk5HNE/AaFChPYvy/Hk4mn6bxTi0RfsCVAUi+Z7UQxJfh2zbepplKu0oPSe322iWkLCJPklV1R3UWRGLWFgI4xaoT6mydRyx+AB+gr2CdftQNiz/kbKKz6v4u4Q7sTJ7iMvSL5mTjYE9k8DKZRFhKxW5qGCrgy4= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 15712543675530.5613085947861691; Wed, 16 Oct 2019 12:32:47 -0700 (PDT) Received: from localhost ([::1]:47484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKp2M-0000qe-GM for importer@patchew.org; Wed, 16 Oct 2019 15:32:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33020) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKouq-0001UT-I3 for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKoup-0002Sa-Fw for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKoun-0002Qv-7Y; Wed, 16 Oct 2019 15:24:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74C0010DCC94; Wed, 16 Oct 2019 19:24:56 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1515C60852; Wed, 16 Oct 2019 19:24:55 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 05/10] image-fuzzer: Use %r for all fiels at Field.__repr__() Date: Wed, 16 Oct 2019 16:24:25 -0300 Message-Id: <20191016192430.25098-6-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Wed, 16 Oct 2019 19:24:56 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This makes the formatting code simpler, and safer if we change the type of self.value from str to bytes. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/qcow2/layout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index 6501c9fd4b..0adcbd448d 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -53,8 +53,8 @@ class Field(object): return iter([self.fmt, self.offset, self.value, self.name]) =20 def __repr__(self): - return "Field(fmt=3D'%s', offset=3D%d, value=3D%s, name=3D%s)" % \ - (self.fmt, self.offset, str(self.value), self.name) + return "Field(fmt=3D%r, offset=3D%r, value=3D%r, name=3D%r)" % \ + (self.fmt, self.offset, self.value, self.name) =20 =20 class FieldsList(object): --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254435; cv=none; d=zoho.com; s=zohoarc; b=keXyp6ICTZ1Hn5oy3g2sOEy84f64aqGaoqEmReyOU62xoYTM1xDReOBUMxE8ZXj9hkxlziNSNlgxln9vXrGnn5Dk7QyCH7es6iL0nQ+tM5WkN7oRbQb1OAEM/A7rVxtUTQWW86Is7meZXEQD4C8ZLZgRoMC9CijLSMm3V10SQnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254435; h=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=YfNl+6QOVMmokSfIYJ+mY19u45f64ZCQuNbM6nHDKCM=; b=MwR2CCQWKj+9aRclrbYvL3yJSINfJ8L5T8OWOsLscw6tZ1HkEDWZCQB1WbnusUdhn8OYrTeuuTYVmvLubeL7yg77kOhb4gPsBOAPWbq8y/Vomrpwq3z+TsTOLx1oweIIfJgFa49spVBra0Mp9QSKb6VUlw+d2m5VeSJW3hOGDB8= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571254435605790.5912252593017; Wed, 16 Oct 2019 12:33:55 -0700 (PDT) Received: from localhost ([::1]:47494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKp3Q-0001ng-SY for importer@patchew.org; Wed, 16 Oct 2019 15:33:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33052) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKouy-0001jy-FN for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKoux-0002W5-2i for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKouu-0002UI-8Z; Wed, 16 Oct 2019 15:25:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D08F877A61; Wed, 16 Oct 2019 19:25:03 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 179145C1D4; Wed, 16 Oct 2019 19:24:57 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 06/10] image-fuzzer: Return bytes objects on string fuzzing functions Date: Wed, 16 Oct 2019 16:24:26 -0300 Message-Id: <20191016192430.25098-7-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Wed, 16 Oct 2019 19:25:03 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" No caller of fuzzer functions is interested in unicode string values, so replace them with bytes sequences. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/qcow2/fuzz.py | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fu= zz.py index 154dc06cc0..c58bf11005 100644 --- a/tests/image-fuzzer/qcow2/fuzz.py +++ b/tests/image-fuzzer/qcow2/fuzz.py @@ -36,11 +36,11 @@ UINT32_V =3D [0, 0x100, 0x1000, 0x10000, 0x100000, UINT= 32//4, UINT32//2 - 1, UINT64_V =3D UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4, UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1, UINT64] -STRING_V =3D ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x', - '%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%2= 0n', - '%%20x', '%%20s', '%s%s%s%s%s%s%s%s%s%s', '%p%p%p%p%p%p%p%p%p%= p', - '%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08= x%%', - '%s x 129', '%x x 257'] +BYTES_V =3D [b'%s%p%x%d', b'.1024d', b'%.2049d', b'%p%p%p%p', b'%x%x%x%x', + b'%d%d%d%d', b'%s%s%s%s', b'%99999999999s', b'%08x', b'%%20d', = b'%%20n', + b'%%20x', b'%%20s', b'%s%s%s%s%s%s%s%s%s%s', b'%p%p%p%p%p%p%p%p= %p%p', + b'%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08= x%%', + b'%s x 129', b'%x x 257'] =20 =20 def random_from_intervals(intervals): @@ -76,12 +76,12 @@ def random_bits(bit_ranges): return val =20 =20 -def truncate_string(strings, length): - """Return strings truncated to specified length.""" - if type(strings) =3D=3D list: - return [s[:length] for s in strings] +def truncate_bytes(sequences, length): + """Return sequences truncated to specified length.""" + if type(sequences) =3D=3D list: + return [s[:length] for s in sequences] else: - return strings[:length] + return sequences[:length] =20 =20 def validator(current, pick, choices): @@ -110,12 +110,12 @@ def bit_validator(current, bit_ranges): return validator(current, random_bits, bit_ranges) =20 =20 -def string_validator(current, strings): - """Return a random string value from the list not equal to the current. +def bytes_validator(current, sequences): + """Return a random bytes value from the list not equal to the current. =20 This function is useful for selection from valid values except current= one. """ - return validator(current, random.choice, strings) + return validator(current, random.choice, sequences) =20 =20 def selector(current, constraints, validate=3Dint_validator): @@ -283,9 +283,9 @@ def header_length(current): def bf_name(current): """Fuzz the backing file name.""" constraints =3D [ - truncate_string(STRING_V, len(current)) + truncate_bytes(BYTES_V, len(current)) ] - return selector(current, constraints, string_validator) + return selector(current, constraints, bytes_validator) =20 =20 def ext_magic(current): @@ -303,10 +303,10 @@ def ext_length(current): def bf_format(current): """Fuzz backing file format in the corresponding header extension.""" constraints =3D [ - truncate_string(STRING_V, len(current)), - truncate_string(STRING_V, (len(current) + 7) & ~7) # Fuzz padding + truncate_bytes(BYTES_V, len(current)), + truncate_bytes(BYTES_V, (len(current) + 7) & ~7) # Fuzz padding ] - return selector(current, constraints, string_validator) + return selector(current, constraints, bytes_validator) =20 =20 def feature_type(current): @@ -324,10 +324,10 @@ def feature_bit_number(current): def feature_name(current): """Fuzz feature name field of a feature name table header extension.""" constraints =3D [ - truncate_string(STRING_V, len(current)), - truncate_string(STRING_V, 46) # Fuzz padding (field length =3D 46) + truncate_bytes(BYTES_V, len(current)), + truncate_bytes(BYTES_V, 46) # Fuzz padding (field length =3D 46) ] - return selector(current, constraints, string_validator) + return selector(current, constraints, bytes_validator) =20 =20 def l1_entry(current): --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254505; cv=none; d=zoho.com; s=zohoarc; b=CVIuNsRxK7g6qIw6e/Eni0H36XMfFzF9MziE5legfAXHXRcaAMSEKxbpprQeromj4iMExCVKQeog+ZoPy28HpUDCON6rc6MB2CXW/IQ9uO9dHv9OhqXNvkKOtCVZY4KUB5DyjPkk06Y6g4B1aCoYRxYx+5QJU29ptMQgE5goOXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254505; h=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=1nqq513z2nt0jgT/U3qQ2Gdu/ZsxIMRlAINwz4wevxI=; b=Zn33z6ykFqxsRkwVbbagzOV0L7Kv6a16DZlqICzQuwr2nq6pVkWox+pQZeEOcPPbMM3xkBsyfFHcZ9pUQwFfDTqgCjINb22W2AJQpqUkJWJ17QzQXEPk1cL+v9Hd7N/N6ZJMkxmYylNzKnpdmY+0gXG79rGU6Qmy4POBD5jPRo0= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571254505757753.8425892323734; Wed, 16 Oct 2019 12:35:05 -0700 (PDT) Received: from localhost ([::1]:47500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKp4a-0002qc-QB for importer@patchew.org; Wed, 16 Oct 2019 15:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33088) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKov6-0001wN-4N for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKov5-0002bH-0C for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKov2-0002YE-Kj; Wed, 16 Oct 2019 15:25:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D88343688E; Wed, 16 Oct 2019 19:25:11 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2763B60852; Wed, 16 Oct 2019 19:25:04 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 07/10] image-fuzzer: Use bytes constant for field values Date: Wed, 16 Oct 2019 16:24:27 -0300 Message-Id: <20191016192430.25098-8-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 Oct 2019 19:25:11 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Field values are supposed to be bytes objects, not unicode strings. Change two constants that were declared as strings. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/image-fuzzer/qcow2/layout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index 0adcbd448d..a0fd53c7ad 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -122,7 +122,7 @@ class Image(object): def create_header(self, cluster_bits, backing_file_name=3DNone): """Generate a random valid header.""" meta_header =3D [ - ['>4s', 0, "QFI\xfb", 'magic'], + ['>4s', 0, b"QFI\xfb", 'magic'], ['>I', 4, random.randint(2, 3), 'version'], ['>Q', 8, 0, 'backing_file_offset'], ['>I', 16, 0, 'backing_file_size'], @@ -231,7 +231,7 @@ class Image(object): feature_tables =3D [] feature_ids =3D [] inner_offset =3D self.ext_offset + ext_header_len - feat_name =3D 'some cool feature' + feat_name =3D b'some cool feature' while len(feature_tables) < num_fnt_entries * 3: feat_type, feat_bit =3D gen_feat_ids() # Remove duplicates --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254567; cv=none; d=zoho.com; s=zohoarc; b=fwJgTKl1/8Tezn3MnWzaLHgPWdzcYWZj2xoeIpQqXxTJ6Z5JpS9xBaunD6SQtnU12o908xeb+6Rf2QAAJgxrK4hOrc1bdtQDgBCf0g6p9YLHqSdx0GzJyNo/uDapa9ahVnSNXqdyFtCGJyQfxZXJl/ZZbBQiH86tTTz2Lmefyc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254567; h=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=jEtz1qFPcZQmMXTOYkczXESIw4GrAyFO96TSALLu9J0=; b=Akq9W5MwN/fl9Tgwx+GPD81tU0mwmYyxIEEWDYADiiTale3xHubB8VcMivFKGeFqga7jIeQjlhLv7mhvCtNQM2zIih+Mwi1JnSNInpQVgqb7iZt19h+uDf2JWVHfJ71jnFLvktBbHeU0xC9vdvc4piy68vynw3uUQQSgXR1sM/M= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 157125456730038.90630824340178; Wed, 16 Oct 2019 12:36:07 -0700 (PDT) Received: from localhost ([::1]:47510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKp5a-00041m-Az for importer@patchew.org; Wed, 16 Oct 2019 15:36:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33104) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKov8-00020C-6V for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKov6-0002e2-Qb for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKov4-0002ZV-MN; Wed, 16 Oct 2019 15:25:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E894D87633; Wed, 16 Oct 2019 19:25:13 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 871ED60852; Wed, 16 Oct 2019 19:25:13 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 08/10] image-fuzzer: Encode file name and file format to bytes Date: Wed, 16 Oct 2019 16:24:28 -0300 Message-Id: <20191016192430.25098-9-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 Oct 2019 19:25:13 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Callers of create_image() will pass strings as arguments, but the Image class will expect bytes objects to be provided. Encode them inside create_image(). Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/qcow2/layout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index a0fd53c7ad..01bff4d05e 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -602,8 +602,8 @@ class Image(object): def create_image(test_img_path, backing_file_name=3DNone, backing_file_fmt= =3DNone, fields_to_fuzz=3DNone): """Create a fuzzed image and write it to the specified file.""" - image =3D Image(backing_file_name) - image.set_backing_file_format(backing_file_fmt) + image =3D Image(backing_file_name.encode()) + image.set_backing_file_format(backing_file_fmt.encode()) image.create_feature_name_table() image.set_end_of_extension_area() image.create_l_structures() --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254128; cv=none; d=zoho.com; s=zohoarc; b=YSFCXkWG6ojWhB3TxkRGqEN3INgUgjcEAd1U1LNz8rproSAbpjp/Nfog4/KKN5+xABLzzGNiQZ1Q1CcDNn68ZJ0fdZo9FtKUVTd9iWrCGeCIdtAMbuTc3KtEQCMLz5aFMscFE1bCsrvkHExT+0yvwcXKbiJvFaWOl26mQzDO5lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254128; h=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=+kshjC9U04E62BQR6ihjJ7yCphQHiqMzhgcLeVqUsrc=; b=OuafRUwcTxxZhphvYHcoAd9sV3ndAN5T9j2tzb54TFcSEyiZFP966l8Ir/h2L8iOOQguj/QDPe5LrD1tHgr9AtWotIWvTzbsuBW2VubRw1nk3AfVax5cDh5FfVqgwmbNQvuU/PQDbOHEPRhfipwRFWTtq+ahE2b4E3NcI+5JRyY= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 157125412812894.57699906081712; Wed, 16 Oct 2019 12:28:48 -0700 (PDT) Received: from localhost ([::1]:47440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoyU-0006Mv-VB for importer@patchew.org; Wed, 16 Oct 2019 15:28:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33179) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKovF-0002Fh-L0 for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKovE-0002kX-8j for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33072) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKovB-0002iH-LK; Wed, 16 Oct 2019 15:25:21 -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 mx1.redhat.com (Postfix) with ESMTPS id DCE3DC057F23; Wed, 16 Oct 2019 19:25:20 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8558160BF7; Wed, 16 Oct 2019 19:25:15 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 09/10] image-fuzzer: Run using python3 Date: Wed, 16 Oct 2019 16:24:29 -0300 Message-Id: <20191016192430.25098-10-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 16 Oct 2019 19:25:20 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" image-fuzzer is now supposed to be ready to run using Python 3. Remove the __future__ imports and change the interpreter line to "#!/usr/bin/env python3". Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/qcow2/__init__.py | 1 - tests/image-fuzzer/qcow2/layout.py | 1 - tests/image-fuzzer/runner.py | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/image-fuzzer/qcow2/__init__.py b/tests/image-fuzzer/qcow= 2/__init__.py index 09ef59821b..ed3af5da86 100644 --- a/tests/image-fuzzer/qcow2/__init__.py +++ b/tests/image-fuzzer/qcow2/__init__.py @@ -1,2 +1 @@ -from __future__ import absolute_import from .layout import create_image diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/= layout.py index 01bff4d05e..57ebe86e9a 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -16,7 +16,6 @@ # along with this program. If not, see . # =20 -from __future__ import absolute_import import random import struct from . import fuzz diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index 94cab5bd93..0793234815 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 =20 # Tool for running fuzz tests # @@ -18,7 +18,6 @@ # along with this program. If not, see . # =20 -from __future__ import print_function import sys import os import signal --=20 2.21.0 From nobody Sat May 18 09:01:27 2024 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571254112; cv=none; d=zoho.com; s=zohoarc; b=Y9Y8Zb6hCOpTSTPpK78CUBmTR3dP6ig67JosJHIDJQks3BQL4/kVFahXw/COiIy+YHChs2poxvu5Dhpw7+CVQRaucAJgTY2yqkTgCq9LnqI16tf6J6hr9M6YTOFsF3P2YccpHxF7EMdrz6NaIJU4fdvV8mP68GSE0FkmtPASJ+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571254112; h=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=CIrP0e1mgqA1qoEtNFKictREHvtywO4CPwJg3YgEm2I=; b=lZFsOgJwRwnHc4c7+16YGEMKpufw4bVwLERwRlTzQgl3xWB4WH9xWkq+mWOXnpUUaniD4rSvtnGLL+Dp1bJMzGxO5QKnEWj79R6dj/XKTclXc5fWmLPvhhwT5zw7ndjgME7glkEmrKmxdPaiav5HAVTTUS//pbA/nVKn8uo+WKM= ARC-Authentication-Results: i=1; mx.zoho.com; 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 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 1571254112949947.7416222853377; Wed, 16 Oct 2019 12:28:32 -0700 (PDT) Received: from localhost ([::1]:47438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKoyF-00060p-PP for importer@patchew.org; Wed, 16 Oct 2019 15:28:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33203) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKovH-0002IK-CI for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKovF-0002ln-UL for qemu-devel@nongnu.org; Wed, 16 Oct 2019 15:25:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKovD-0002jd-M4; Wed, 16 Oct 2019 15:25:23 -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 mx1.redhat.com (Postfix) with ESMTPS id E718B18CB904; Wed, 16 Oct 2019 19:25:22 +0000 (UTC) Received: from localhost (ovpn-116-20.phx2.redhat.com [10.3.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 854CE60BF7; Wed, 16 Oct 2019 19:25:22 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 10/10] image-fuzzer: Use errors parameter of subprocess.Popen() Date: Wed, 16 Oct 2019 16:24:30 -0300 Message-Id: <20191016192430.25098-11-ehabkost@redhat.com> In-Reply-To: <20191016192430.25098-1-ehabkost@redhat.com> References: <20191016192430.25098-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Wed, 16 Oct 2019 19:25:22 +0000 (UTC) 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: 209.132.183.28 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: Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of manually encoding stderr and stdout output, use `errors` parameter of subprocess.Popen(). This will make process.communicate() return unicode strings instead of bytes objects. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow --- tests/image-fuzzer/runner.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index 0793234815..4ba5c79e13 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -79,16 +79,13 @@ def run_app(fd, q_args): devnull =3D open('/dev/null', 'r+') process =3D subprocess.Popen(q_args, stdin=3Ddevnull, stdout=3Dsubprocess.PIPE, - stderr=3Dsubprocess.PIPE) + stderr=3Dsubprocess.PIPE, + errors=3D'replace') try: out, err =3D process.communicate() signal.alarm(0) - # fd is a text file, so we need to decode the process output before - # writing to it. - # We could be simply using the `errors` parameter of subprocess.Po= pen(), - # but this will be possible only after migrating to Python 3 - fd.write(out.decode(errors=3D'replace')) - fd.write(err.decode(errors=3D'replace')) + fd.write(out) + fd.write(err) fd.flush() return process.returncode =20 --=20 2.21.0