From patchwork Wed Jul 15 22:32:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 92618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55A81C4450A for ; Wed, 15 Jul 2026 22:32:49 +0000 (UTC) Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.846.1784154765476818093 for ; Wed, 15 Jul 2026 15:32:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=PEV4Rmvh; spf=pass (domain: gmail.com, ip: 209.85.219.53, mailfrom: twoerner@gmail.com) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-9034b6b7674so45007496d6.0 for ; Wed, 15 Jul 2026 15:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784154764; x=1784759564; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=LJnVhbwgK3az62VYfzpnKRYs1hsdCouYMhzvSto6YWE=; b=PEV4RmvhkJ/3f829XBZSEDLplBMJykRK93AyRQ8+V1Zt1EW8WhMRBBU2kh+cK4Hy/z tjJcHxs4zYzPv6eadjAUfuz8g4E/1Ykvc7MVLCs5KbAoWGGH8HZwMAubAFGK8UQPBRvK AvO4cl3ekeyBhP5NkqJ20dBY4WORVVGfL8iDRggwGaZd6HaFFFgTVqpd1nxyheuqmx65 pL5Ba0/AAQdTI68ja5sB3xyBVqEx9znCNsV5wGhqFV3lCMrlVGgNvNZGOZx+6M6Udw6k 5SpnfL00sKDvW71C5URJwJ99VDz1WsLpyMbgkdtYyve15pdlgVH16tfKEhkzQhQcQ4xG zeBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784154764; x=1784759564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=LJnVhbwgK3az62VYfzpnKRYs1hsdCouYMhzvSto6YWE=; b=HFEbf1PFebah8wlkKJ7aNzkXKA55OdNE78K1G2ePLhJKXjOSjLlSp10xo3tXB8/Jek 82BQd8+TLCTHwb3NP30MhFyMFrous0yFnH4iPbhzQlMH/SQh8TRdyF9wWyA7/8LCxIqL 3sGxq57pAEMfvy7ncZRoJnbyeSvNhBolaOR9/QGsmKxnkZQqWZrPIkj7S6v+EXhf1/tP GWv1KBaXzOl7vjxm/nM0qnXKf85O1u23Pq7SmAybUvnPpCmRaXAhYZZD5OIKi+8z0gfl z3kEUqkjI6GC4gAWhY2c0+IzkX9diSG/XjYQlbO3b2iRTKamX46dGuIdPen9x+HnCanz 4maQ== X-Gm-Message-State: AOJu0YxY+7Q0Sjf3rc1t/QnLvkoxFy9IVyyJcGOtFEGrBMjsi5kNbcre IiV2SM/q2cu8TcH310oGMF3ZloND4ERM8C0H7dPEMRkAM/mzzYvVWfQ99vnNQQ== X-Gm-Gg: AfdE7cn7J61CG4e6x5HlJzrbNTw30OMJFw0fCNqf3C4qoYDQDtjS0OJhq/d45/O9xH2 rCDTQ0XS4hOlfGmCnA0CXd0DSU4jioLoIxH+D+qwhYu72VOEVL7mhOBT+Fm/QFo39CXvGIi7GLu R0UYNbMX9pgxrnYksgWGfYt9+GTdapZjIi5jn7yBwxPUie7gdfl6AeRH8hCYKbuMz5JfNsGG4JM UFnSV5MmbwenlPJnKmODM5NxYhlnwJcKMorY6R6g5qfnoLNxeBibXsMori/P8ykUSegVMId7NRL IQ7JJ4ru7Q8Il+fvhCzp9ioRhXvnvUVDi+7mztsWqrG7uJxKCuRO8fVCSzbvpj+cL6giZ+fjMIR X7qoIh5ev1m3jrvr9uvYm+drXmdLng2gSL0RTTOcFIVbprkJ23JUvoYyM44cjk/9Vl2IEC6Ra1O KjkJBkPZ3esOI4fDKh5jDx99v9Z1F1opBBuDIUCNilLMqG X-Received: by 2002:a05:6214:2465:b0:8ff:6304:da9 with SMTP id 6a1803df08f44-90747c2ef20mr116965116d6.6.1784154764184; Wed, 15 Jul 2026 15:32:44 -0700 (PDT) Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd81f43e6sm205883726d6.39.2026.07.15.15.32.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 15:32:43 -0700 (PDT) From: Trevor Woerner To: yocto-patches@lists.yoctoproject.org Subject: [wic][PATCH 1/5] ksparser: reject negative sizes in sizetype() Date: Wed, 15 Jul 2026 18:32:22 -0400 Message-ID: <20260715223226.3371498-2-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260715223226.3371498-1-twoerner@gmail.com> References: <20260715223226.3371498-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 15 Jul 2026 22:32:49 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4485 sizetype() splits "[S|s|K|k|M|G]" into an integer count and a unit suffix, then multiplies. int() happily parses a leading minus, so "-1M" produced -1024 and "-5" produced -5120 with no complaint. A negative size is meaningless for every consumer of sizetype() (--size, --fixed-size, --offset, --extra-*-space, and the empty source plugin's size=/bs= params); it can only corrupt the resulting image layout. Reject a negative size with the same ArgumentTypeError the parser already raises for other malformed sizes. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner --- src/wic/ksparser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wic/ksparser.py b/src/wic/ksparser.py index 8e5fbfadd81f..24c7015b336d 100644 --- a/src/wic/ksparser.py +++ b/src/wic/ksparser.py @@ -68,6 +68,8 @@ def sizetype(default, size_in_bytes=False): except ValueError: raise ArgumentTypeError("Invalid size: %r" % arg) + if size < 0: + raise ArgumentTypeError("Invalid size: %r" % arg) if size_in_bytes: if suffix == 's' or suffix == 'S': From patchwork Wed Jul 15 22:32:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 92619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E93DC44507 for ; Wed, 15 Jul 2026 22:32:49 +0000 (UTC) Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.847.1784154766961523451 for ; Wed, 15 Jul 2026 15:32:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=OX7ymLax; spf=pass (domain: gmail.com, ip: 209.85.222.182, mailfrom: twoerner@gmail.com) Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-92e5c9211d2so465444085a.1 for ; Wed, 15 Jul 2026 15:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784154766; x=1784759566; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=X9+QoDSp9pMkV1VzPHZkid1oJcoMg6nv+SazO+k7r+4=; b=OX7ymLaxu2JvaFNPYpJop2H4Bituzlg/2fO41cinyVaM4RxQgNbs9y1p+yH5mdG1te 1r/Sm37uJn/MW9ObHQhwXkSVIbdDqrAJNs0EWOyEEue482aZEzdk129n2pFWu+n/cGPX F648Ghzpn/pXTnU9ctbVgbiz94ymKszla0uEIZ2bFmE39pUrSU3llE+iumY1O5woJR7H T1CQnZE5Hr5UsKQ76HXx1sN/+uewDRIfdU5CQdYeMi7XAHkLNX5xE6YFoGVdVqYGqzOU Ou+6UKeknZn8Ydjr2Uz5HjnlHcYTzPKedQYULKnnJBe/yEWjG0PNhVFOll7Kubv3jHLw oYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784154766; x=1784759566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=X9+QoDSp9pMkV1VzPHZkid1oJcoMg6nv+SazO+k7r+4=; b=BqEMNlD2wK3n9sS7QmQlAUQh90njf+mrpo1uOvL8FyXfJ0FXPMWYZw8c3JzMQGstvi IvbqhIMURYULF4y9PdOi0KZdSYlc1L+ymYUcQ+XyQNgNdM1c4aTyKoMdC+FCQECC3AhZ JwA0E2ue/IONPb7H0E1gzTCeFz+Kca09+cZmx2k+ZVEAoi038m/gWun7X/RtbRHbWE/1 4VKi4VGP8i1DU5L+F6LBKC1TXUfs7IeVmV1voCiFxWEUqnqVVTrAD4289rK9/Xr0pkt9 JwwIehMtNYog4dSoYrpRwaOUiifPaxPNVDTQkoVc3EQz31b6BKjivpdgEVKNM2QL7Vdz sVew== X-Gm-Message-State: AOJu0YwvTeKYtzNRlgEbfe0C74xURBq3dqxE8FmNPOHdQLRIvkEfl8zC COUNZHpeVQaCJ3XwyIJroO0Kbkxbu113LhrllgYPzGQYLwcy0MV7PVAdcSO4eg== X-Gm-Gg: AfdE7cmYTjTaIqqVEQZaHISr/40kaBL+uVKw/QTNhAP8z1zqk1gMmtZOHgfKzpK085n z6QfBbFmY3M35+yfnRjzZx2zpisg/Iz2aHV9UB/6pq91gb8ZZMsqpTqoUP/9Lqkl2RfjMvne3rv Sgy0yQJzUPJW6vOvzSB4EGX20YkZ92AhM+QbMSvEMb5QukfY9UYzR0HgU1PFoaYl76z1CT4TdoU mJBUNwqUHZg8k3GcqHTx3HKNqEIBoZEAx5nOKfkuInN23pugoULKH4GKVamlvs1zHqXlbqJ4xW6 YqQTyHtLp52Dmp6oB+LGmEk8yABqhVZZJyLpWiJqhRdHxp4gc9V2Ug2nPTnoTE3gedhJZgGLyR4 R/OXsi3QvzOwQayJhQlikhjyBhDQDNN0wbUkZkxwfZxfXO1cZdYoWOT0KKaMyT/Wid0q1JGYaZc ZYHHAgApf3hWI2Q9TBoQt0f90SlrzYlt1ru4zNZV4qd0zg X-Received: by 2002:a05:620a:25ca:b0:92e:c118:18b5 with SMTP id af79cd13be357-930963feca4mr515121085a.84.1784154765584; Wed, 15 Jul 2026 15:32:45 -0700 (PDT) Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd81f43e6sm205883726d6.39.2026.07.15.15.32.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 15:32:44 -0700 (PDT) From: Trevor Woerner To: yocto-patches@lists.yoctoproject.org Subject: [wic][PATCH 2/5] ksparser: fix crash on out-of-range overhead factor Date: Wed, 15 Jul 2026 18:32:23 -0400 Message-ID: <20260715223226.3371498-3-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260715223226.3371498-1-twoerner@gmail.com> References: <20260715223226.3371498-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 15 Jul 2026 22:32:49 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4486 overheadtype() rejects a factor below 1.0, but the error path read raise ArgumentTypeError("Overhead factor should be > 1.0" % arg) The message string carries no %-placeholder, so the `% arg` interpolation itself raised TypeError ("not all arguments converted during string formatting") before the ArgumentTypeError could be constructed. Every out-of-range value (0.0, 0.5, -1.0, -inf) crashed with an opaque TypeError instead of the intended argument error. Add the missing placeholder so the offending value is reported and the correct ArgumentTypeError is raised. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner --- src/wic/ksparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wic/ksparser.py b/src/wic/ksparser.py index 24c7015b336d..a73ae56cd196 100644 --- a/src/wic/ksparser.py +++ b/src/wic/ksparser.py @@ -99,7 +99,7 @@ def overheadtype(arg): raise ArgumentTypeError("Invalid value: %r" % arg) if result < 1.0: - raise ArgumentTypeError("Overhead factor should be > 1.0" % arg) + raise ArgumentTypeError("Overhead factor should be > 1.0, not %r" % arg) return result From patchwork Wed Jul 15 22:32:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 92621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55AB7C44507 for ; Wed, 15 Jul 2026 22:32:59 +0000 (UTC) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.883.1784154769116344371 for ; Wed, 15 Jul 2026 15:32:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=mxGH9hWo; spf=pass (domain: gmail.com, ip: 209.85.160.171, mailfrom: twoerner@gmail.com) Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-51c0cea8883so22670271cf.1 for ; Wed, 15 Jul 2026 15:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784154768; x=1784759568; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=DGZA0SHlucguA9WNdVCmxl44jhm0wTT6MA5FUnD/Rqc=; b=mxGH9hWoaT0tp2NztBy4kJeCu5HV1YdtJfXbmZkM44tIofiqgvnVyOVf8mQf0lHXvH EkYju/3PZDDFmbC0rvSHX3R2wElsiRmfbQg7J2lZqI7OTZbE5EXnLIKoodKsoQxMeC1j f1H9iB3sCaKJArgAqhOq6vrInUaTURAvuuhOJiEYN5FEG+O69cF/svKTE/ecDfBBg84L eVByNGlky3iBI9qed6ojr2S0HQ35IuWrdzhakPHc757VXOW1XL6N396r/sMRTpGuoTLJ RYVFYtQLU5D5B7dANCP4TE4qlYmuwnb2/pIazKNfi0OFposUJOefgdX8mK7eH8lDtofl OSIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784154768; x=1784759568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=DGZA0SHlucguA9WNdVCmxl44jhm0wTT6MA5FUnD/Rqc=; b=JVSqcHHUS9wT8Z+BK23afqybkbFPYFz09qaub+NjsEiZ04/3Ao483GNix8wArgZnEW WXPljjNeKLujBZLxtux6noOx1t+cWqnDNqoUd4i4kSHmBieKGCfyfGvVaHjK9iZM/7Je DlYmoG0CLOsGmq3Dp0t5URyOmmruNFDjDNsJPb9UGs+gZfVDc7hQFptIuhyr3qFDk2MH 9eZHbkNCaubfVsE9LmYgSbJEjfOsXQN/CEdbfwwZJgR9Co/jK3cf9mfWi9E2jh4e5qaZ URc6eerQvyiIngxssBSeSMm50uV/xtuHZClBenc+U/yhuUr/VUNilmtDn25RXEJzcj6k uF9g== X-Gm-Message-State: AOJu0Yz+qUnrWn4yzn6xivWtQBAS2qc+HmMxCQzyw9jHKRKtIzXE/lAx zIk2fTpOtWtfg2G9+h9B+lFyv0MUUUVyun56bk9XvtJvXq1Y6pCnAJHi6Ji9pQ== X-Gm-Gg: AfdE7cmh0SnFa/0cu+uYCN7JrlV9VeqtLPT4yjcwhkNsQbYn4Mw6WaMb0lWgvXgHFSB ZWMGycWTNltwBDcGF2iwFr7fyKnj3b/gpBCMMk2uang0w1q2uNiVg8TPngICttC9lY+k1v5sGp4 QKtrJLE4FOlJj26sYgJIJE/VrHn/iUmJP98xA8T/+jXsJ69IfOAXEn4k5ivaQfPigQkcqCYtmfA u99z9KoMAalNkFbM1NChgL88asjm3Fj38SKn6j4vrqUS1slZsFl/bfDB2K3ffBY9mtTRqVZLYK/ Rh1Rz6pQN/YRkDCk0apQYMctleCav1LqsMxuMcwSKwA0GhIuHuEXXIsXJ7G/uTjOqAccRj09L1D 9TPOS2Z6+iQED5W09dq/kg7zfDMjw28dNyqrDcp3m8zRhlHbzWnkJct6uv4zWvspzEzIEFR4SoJ 2Dn++CCo3o5PsPhhLUMNVA7TikiysEFul46ww3EtYJkzXm X-Received: by 2002:a05:622a:4d2:b0:51b:fe30:b8d5 with SMTP id d75a77b69052e-51fc1971cbamr175091cf.29.1784154767775; Wed, 15 Jul 2026 15:32:47 -0700 (PDT) Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd81f43e6sm205883726d6.39.2026.07.15.15.32.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 15:32:45 -0700 (PDT) From: Trevor Woerner To: yocto-patches@lists.yoctoproject.org Subject: [wic][PATCH 3/5] ksparser: reject non-finite overhead factors Date: Wed, 15 Jul 2026 18:32:24 -0400 Message-ID: <20260715223226.3371498-4-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260715223226.3371498-1-twoerner@gmail.com> References: <20260715223226.3371498-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 15 Jul 2026 22:32:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4487 overheadtype() guards against factors below 1.0, but float("nan") and float("inf") slip past that check: nan compares false against every bound, and inf is trivially greater than 1.0. wic then multiplied the rootfs size by nan or inf (partition.py does int(rootfs_size * self.overhead_factor)), producing a ValueError deep in image sizing or a nonsensical partition size. Reject any non-finite factor up front with math.isfinite() so the error is reported at parse time alongside the other overhead validation. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner --- src/wic/ksparser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wic/ksparser.py b/src/wic/ksparser.py index a73ae56cd196..528a8180826f 100644 --- a/src/wic/ksparser.py +++ b/src/wic/ksparser.py @@ -15,6 +15,7 @@ import os import shlex import logging +import math import re import uuid @@ -98,7 +99,7 @@ def overheadtype(arg): except ValueError: raise ArgumentTypeError("Invalid value: %r" % arg) - if result < 1.0: + if not math.isfinite(result) or result < 1.0: raise ArgumentTypeError("Overhead factor should be > 1.0, not %r" % arg) return result From patchwork Wed Jul 15 22:32:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 92620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 641FCC44501 for ; Wed, 15 Jul 2026 22:32:59 +0000 (UTC) Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.849.1784154771089480134 for ; Wed, 15 Jul 2026 15:32:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=mpKL5MXl; spf=pass (domain: gmail.com, ip: 209.85.219.46, mailfrom: twoerner@gmail.com) Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-90004d2f7b7so76212026d6.1 for ; Wed, 15 Jul 2026 15:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784154770; x=1784759570; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Cox+V5NfMGBoTovzmcyCjkMvC5wJztFakUujrKVvb+A=; b=mpKL5MXliT9f466Til4tllpXhghhjQwnK43XLgdgDZLcGBfYZDtwPKSdB3xtbywgCQ fAlRlWwMq7qek3Ka/t1Z4Ye9saRoAa2AQT+RKDrcFSulLGc8jaeAaydGOAQMXBmO3cG2 LRaBIDUcKSbyYCXgZDbyvEFZfgd7gugwJpe7radFA+HDvHVMeiEFGkvVPLEuY1Wwo4Vt IOehl30pGWcgrQDqWeku2nHJOo3AQfvkRwupdqRbDAnINiLB1fwNDEq/u7JYm3N+ZbZK d0LfZ6quz+bXN9RSZrVifTEkDAZABmulCeLa9tg6jmXlVa1wqfzc0o5wbpeZPvbGayQ0 9U2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784154770; x=1784759570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Cox+V5NfMGBoTovzmcyCjkMvC5wJztFakUujrKVvb+A=; b=RqZyy3dpwp0oGFxbxIvSgLaqf7uz7K9cawIvKKidKLc9TS29xckLJPphbH94tAsEoc opWnnJUwMD6rw8SZVxRUP71TNdrg29lvzP2kWRpYmYVkANGfszWsEmZRwbkfoZPi5zjd r0447a2Pf1dcEDgUM5Kr0sz7SK5vBuHY0Ht2JwrnfIOheTg+U1XYFFzyeILwelvuUilc OG6/vp/2gn2YqW4yCPoK1pieyn2mnnQc4nQ2VeMdOoK/mjsqRY5W4HEa8sh3ui9x7Tkj 5GB93X2SChVKtBxXMSsn+KBNiJC+ieFE+mePrvus1sXU/2J4UtDfRjWmp8rJK4NFWoPG iBWQ== X-Gm-Message-State: AOJu0YwpcQFQP9/FuM8gB6q9b8zr7Li81V5XB3ZrjDJ7VbyHY+qezodb 6aQyJE3vz+xT4N1z620MF1w2aNOo81S+YZicSaL1z+BM9TvuoS4CgCC2v5c50w== X-Gm-Gg: AfdE7cmOEJDOMigosvUbr3yIhkkFGp9/t7XeXLpBQO5EWAfOfgNHjNM7IUIUTgohHZr pOcQ0jbf8Lon1IDLwXKworQw0EQp9Z7O34kxfq1GJ638FtsX3lyfsfll8ubbso6PQxBWTzyfRIA n6SPFVJenwPSWJgEfk0ilJdwXQ+vfsXrEsWjyZbQOfcVXJnS59aeGHthM9ehOzYu2szLHAPzBVL 0u8HXJwKP4o6XKO3qFmWB7dz29b/yLMhR76z+CP3fAdDTZxOqMRQ16QEZkFEDDm4s070bb9yiOA SGI8yfZEuPhXrLbKfzN7pfpJVAB7eSmQyFL2SFNED3+ZX5V7Z4mW0s9E/e+jpgdF/4gbNPbFWfg ilFSYyF/qARX43QJyyBFq3D1r61NY8LpGillhilfUHxMvZ0SIrdaFc96IwF6+LHmIfLuID8KtMX JcRGJK4I8DdpwQYZJgSTSYCFwaXK5eyp/R25hXVNQnGj+G X-Received: by 2002:a05:6214:440b:b0:8f1:7a7:b869 with SMTP id 6a1803df08f44-90758deb9camr56865366d6.31.1784154769831; Wed, 15 Jul 2026 15:32:49 -0700 (PDT) Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd81f43e6sm205883726d6.39.2026.07.15.15.32.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 15:32:48 -0700 (PDT) From: Trevor Woerner To: yocto-patches@lists.yoctoproject.org Subject: [wic][PATCH 4/5] ksparser: require an explicit 0x prefix for --system-id Date: Wed, 15 Jul 2026 18:32:25 -0400 Message-ID: <20260715223226.3371498-5-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260715223226.3371498-1-twoerner@gmail.com> References: <20260715223226.3371498-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 15 Jul 2026 22:32:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4488 systemidtype() validates the MBR partition type as "hex between 0x1 and 0xFF", but it converts with int(arg, 16), which also accepts a bare "82" (parsed as hex 0x82 = 130) and a signed form like "+0x82". Those inputs contradict the documented contract and are silently returned unchanged, so the raw string later handed to sfdisk may not be what the user meant. Require an explicit 0x/0X-prefixed hex string before converting, so only the documented form is accepted and every other spelling raises the existing ArgumentTypeError. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner --- src/wic/ksparser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wic/ksparser.py b/src/wic/ksparser.py index 528a8180826f..dcf26f788083 100644 --- a/src/wic/ksparser.py +++ b/src/wic/ksparser.py @@ -132,10 +132,12 @@ def systemidtype(arg): """ error = "Invalid system type: %s. must be hex "\ "between 0x1 and 0xFF" % arg - try: - result = int(arg, 16) - except ValueError: + # int(arg, 16) also accepts a bare "82" (-> 130) and a leading sign + # like "+0x82"; the documented contract is an explicit 0x-prefixed + # hex byte, so require that form before converting. + if not re.fullmatch(r"0[xX][0-9a-fA-F]+", arg or ""): raise ArgumentTypeError(error) + result = int(arg, 16) if result <= 0 or result > 0xff: raise ArgumentTypeError(error) From patchwork Wed Jul 15 22:32:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 92622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73148C4450A for ; Wed, 15 Jul 2026 22:32:59 +0000 (UTC) Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.887.1784154773056621771 for ; Wed, 15 Jul 2026 15:32:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=a2ODggNE; spf=pass (domain: gmail.com, ip: 209.85.219.53, mailfrom: twoerner@gmail.com) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-8f0d6853360so43297776d6.0 for ; Wed, 15 Jul 2026 15:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784154772; x=1784759572; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Hzknf4H9TyLnXFxGkY4rAzItZggB8hKQ5vgDhzh529s=; b=a2ODggNECpAOLKizVndNx2ykl/moBBhE1NsNgMw9KvNgkL4GttuZbkEZleErB4VUaf k/ZzIbeRGme98TWoFmsIVhmGaZazYs/KBEvgs6W2asPUA2lF1gkM8r9kqmTfGAHWBYr8 DRyZtL/0ex/9vaYkaLI6qxgs44vGXIN/ZYHCuH9LTR82YxuqOH3AvpsMBLbh3w8P72A3 afWQtK2DA4USN1PdeF+g5xsOwH4yLUSkRNLb17v/xFo11H3vd3iRO/Ou2EBaWoI2cA3g JiOQdL4DKF+Hz0zwggsfFFfpTGCGRtAkO4aNHTV1gA46M9v+n8umKoj5HXA3rvV0Vhn2 xDAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784154772; x=1784759572; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Hzknf4H9TyLnXFxGkY4rAzItZggB8hKQ5vgDhzh529s=; b=c4co9EjgB8LY+2M9tRqjxZZ6UIvoKbZAi+ax+6Ew9wdDafQvTr42Bv3q6dnPv1fi37 Tb+jJfebVoAuQ04biEFLNLrv5uO8UX0HvVKIgVUnWynkydGd4aMs1d9eQwZWADsrZas4 1vp0d3fdrBqADOHTQZz2pdOvj1yxaFGAp6aE2PhzWn+VwTfRmTbJjviAWqFhL9T+2sgA L3sKe3+zYtBDqcNy1OT2iUCUigIBugoq067ZneKu4c6bS18tyYz2SEZq1RU8kFdkr8Np thHDMVGxZpMNShUDhbEpeE06aLyKcS6pwn8CuQsbbHxoM6SoyHg4Q3tOBgyAClBPcZz8 YmSw== X-Gm-Message-State: AOJu0YyFLFsTOweg+TNaalp3pcO0bA1xPXSuBI/J3KDs+HKeI490MnsJ LNAPM/2gADifj9cLCodg2DfhMfssN/khaVgRIKO6zOQQNz5C1Qero50EY9MEOw== X-Gm-Gg: AfdE7cne0ec/AiU8NuQq4AkHxJRC92w5DtC5NzDJyNPTMdRN+0dsEYuxEstDF8GkEUi rCDD2A/atQV2l/ryfJK/CaZ6Z9PYKfOV60n/7gH0oHT/THeKA2qlKgFd5/2tHHSixMr0K1NTBLL MM74xFuo1ReiwLo+xiRvW3l8kGy/4QCooxPjK99OUymnOifdD8QBxCYGEUGgvVTjR3F5nNvG/UR GcZuJ8gPF1uJamwh9zTz//GNj6w76haJBnJAq5aMZ2PzTnaYwE31VO7K97BWXZ1Q86r1k1PYspH Rw56B5htx+EkmJyrbnLLW5QjNbSySsqHsLwdYjussHjhMRSVY+1YIvJjPKqCL/PTAndw1FTiz+q o70OetPR4Dmjy+nVnG8fJf6TPdQqPlq6MGIZ4iEBgqfnP+VMghZAyujzIXygEydhGEH4syBV9AP 8VByCQPSbjakcU1pSL0gxGd3icuwj2eVuzii0zbZh2upnU X-Received: by 2002:a05:6214:500e:b0:8ef:5b18:65ec with SMTP id 6a1803df08f44-9074c70b5cemr93457776d6.15.1784154771681; Wed, 15 Jul 2026 15:32:51 -0700 (PDT) Received: from localhost.localdomain (pppoe-209-91-167-254.vianet.ca. [209.91.167.254]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd81f43e6sm205883726d6.39.2026.07.15.15.32.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 15:32:50 -0700 (PDT) From: Trevor Woerner To: yocto-patches@lists.yoctoproject.org Subject: [wic][PATCH 5/5] tests/unit/test_ksparser_types: cover ksparser's argparse types Date: Wed, 15 Jul 2026 18:32:26 -0400 Message-ID: <20260715223226.3371498-6-twoerner@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260715223226.3371498-1-twoerner@gmail.com> References: <20260715223226.3371498-1-twoerner@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 15 Jul 2026 22:32:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4489 Add direct unit coverage for sizetype(), overheadtype(), and systemidtype(): the accepted KiB/byte-mode units and default-suffix handling, the >= 1.0 overhead contract, and the 0x-prefixed system-id byte range, together with the boundary and malformed inputs each rejects. The cases pin behaviour that is easy to regress: sizetype() rejects a negative count, overheadtype() raises a clean ArgumentTypeError (not a TypeError) for a sub-1.0 factor and refuses nan/inf, and systemidtype() accepts only an explicit 0x-prefixed hex byte. AI-Generated: codex/claude-opus 4.8 (xhigh) Signed-off-by: Trevor Woerner --- tests/unit/test_ksparser_types.py | 226 ++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 tests/unit/test_ksparser_types.py diff --git a/tests/unit/test_ksparser_types.py b/tests/unit/test_ksparser_types.py new file mode 100644 index 000000000000..49ac38ba5397 --- /dev/null +++ b/tests/unit/test_ksparser_types.py @@ -0,0 +1,226 @@ +""" +Unit tests for wic/ksparser.py's custom argparse types: sizetype, +overheadtype, and systemidtype. These are wic's own input validators for +kickstart/command-line values, so the tests pin the accepted forms, the +rejected forms, and the boundaries between them. +""" +import sys +from pathlib import Path + +import pytest + +_SRC = Path(__file__).resolve().parent.parent.parent / "src" +if str(_SRC) not in sys.path: + sys.path.insert(0, str(_SRC)) + +from argparse import ArgumentTypeError + +from wic.ksparser import sizetype, overheadtype, systemidtype + + +class TestSizetype: + """sizetype(default, size_in_bytes=False) returns f(arg) that turns a + "[S|s|K|k|M|G]" string into an integer. With size_in_bytes=False + the multiplier is 1 (K->1, M->1024, G->1024*1024, i.e. KiB counts); + with size_in_bytes=True the multiplier is 1024 and S/s means sectors of + 512 bytes. A bare number takes the default suffix.""" + + @pytest.mark.parametrize("arg,expected", [ + ("0", 0), + ("0M", 0), + ("1K", 1), + ("1k", 1), + ("3K", 3), + ("7K", 7), + ("512k", 512), + ("999k", 999), + ("1024K", 1024), + ("1000K", 1000), + ("1M", 1 * 1024), + ("10M", 10 * 1024), + ("13M", 13 * 1024), + ("100M", 100 * 1024), + ("512M", 512 * 1024), + ("1G", 1 * 1024 * 1024), + ("2G", 2 * 1024 * 1024), + ("3G", 3 * 1024 * 1024), + # a large magnitude past 2**31, to catch any 32-bit truncation + ("5000000K", 5000000), + ]) + def test_kib_units_with_M_default(self, arg, expected): + assert sizetype("M")(arg) == expected + + def test_bare_number_uses_M_default(self): + assert sizetype("M")("100") == 100 * 1024 + + def test_bare_number_uses_K_default(self): + assert sizetype("K")("512") == 512 + + @pytest.mark.parametrize("arg,expected", [ + ("1S", 512), + ("1s", 512), + ("2S", 2 * 512), + ("7S", 7 * 512), + ("1K", 1024), + ("3K", 3 * 1024), + ("17M", 17 * 1024 * 1024), + ("1M", 1024 * 1024), + ("1G", 1024 ** 3), + # past 2**63 to confirm Python's arbitrary-precision ints hold + ("10000000G", 10000000 * 1024 ** 3), + ]) + def test_size_in_bytes_units(self, arg, expected): + assert sizetype("K", size_in_bytes=True)(arg) == expected + + def test_sectors_only_when_size_in_bytes(self): + # 'S' is a valid suffix only in byte mode; without it the suffix is + # unknown and rejected. + with pytest.raises(ArgumentTypeError): + sizetype("M")("1S") + + # --- suffix case sensitivity ------------------------------------------- + + @pytest.mark.parametrize("arg", ["1m", "1g"]) + def test_lowercase_m_and_g_rejected(self, arg): + # Only k/K are case-insensitive; m and g are not accepted. + with pytest.raises(ArgumentTypeError): + sizetype("M")(arg) + + # --- negative sizes ----------------------------------------------------- + + @pytest.mark.parametrize("arg", ["-1M", "-5", "-1K", "-1024K", "-1G"]) + def test_negative_size_rejected(self, arg): + with pytest.raises(ArgumentTypeError): + sizetype("M")(arg) + + # --- invalid formats ---------------------------------------------------- + + @pytest.mark.parametrize("bad", [ + "abc", # no digits + "M", # suffix only + "1X", # unsupported suffix + "1.5M", # float not accepted + "1M ", # trailing space becomes the suffix + "1e3M", # scientific notation + "", # empty + " ", # whitespace only + "1;M", # shell metacharacters + "1|M", + "$(1)M", + "1`M", + ]) + def test_invalid_format_rejected(self, bad): + with pytest.raises(ArgumentTypeError): + sizetype("M")(bad) + + def test_none_rejected(self): + with pytest.raises((ArgumentTypeError, TypeError)): + sizetype("M")(None) + + +class TestOverheadtype: + """overheadtype(arg) -> float, and the factor must be >= 1.0. Anything + below 1.0, non-numeric, or non-finite is an ArgumentTypeError.""" + + @pytest.mark.parametrize("arg,expected", [ + ("1.0", 1.0), + ("1.001", 1.001), + ("1.1", 1.1), + ("1.3", 1.3), + ("1.37", 1.37), + ("3.14159", 3.14159), + ("7", 7.0), + ("2", 2.0), + ("2.0", 2.0), + ("100.0", 100.0), + ("1000000.0", 1000000.0), + ]) + def test_valid_factor(self, arg, expected): + assert overheadtype(arg) == pytest.approx(expected) + + def test_leading_whitespace_accepted(self): + # float() strips surrounding whitespace. + assert overheadtype(" 1.1") == pytest.approx(1.1) + + def test_trailing_whitespace_accepted(self): + assert overheadtype("1.1 ") == pytest.approx(1.1) + + # --- below 1.0: a clean ArgumentTypeError, not a TypeError crash -------- + + @pytest.mark.parametrize("arg", ["0.0", "0.5", "0.999", "-1.0", "-0.5"]) + def test_below_one_rejected(self, arg): + with pytest.raises(ArgumentTypeError): + overheadtype(arg) + + # --- non-finite --------------------------------------------------------- + + @pytest.mark.parametrize("arg", ["nan", "NaN", "inf", "Infinity", "-inf"]) + def test_non_finite_rejected(self, arg): + with pytest.raises(ArgumentTypeError): + overheadtype(arg) + + # --- non-numeric -------------------------------------------------------- + + @pytest.mark.parametrize("bad", [ + "abc", "1.1.1", "M", "1,3", "1 1", "--1.1", "", + ]) + def test_non_numeric_rejected(self, bad): + with pytest.raises(ArgumentTypeError): + overheadtype(bad) + + def test_none_rejected(self): + with pytest.raises((ArgumentTypeError, TypeError)): + overheadtype(None) + + +class TestSystemidtype: + """systemidtype(arg) validates an MBR partition type id as an explicit + 0x-prefixed hex byte in 0x1..0xFF and returns the original string + unchanged.""" + + @pytest.mark.parametrize("arg", [ + "0x1", "0x01", "0x0b", "0x0B", "0x82", "0x83", "0xFE", "0xFF", + "0xff", "0xFf", "0X82", + # odd, non-round bytes across the range + "0x7", "0x2a", "0x5b", "0x93", "0xa7", "0xd3", + ]) + def test_valid_returned_unchanged(self, arg): + assert systemidtype(arg) == arg + + # --- out of range ------------------------------------------------------- + + @pytest.mark.parametrize("arg", ["0x0", "0x00", "0x100", "0xFFFF"]) + def test_out_of_range_rejected(self, arg): + with pytest.raises(ArgumentTypeError): + systemidtype(arg) + + # --- must be an explicit 0x-prefixed hex string ------------------------- + + @pytest.mark.parametrize("arg", [ + "82", # no 0x prefix (would parse as hex 130) + "130", # decimal that names a valid value + "+0x82", # leading sign + "-0x82", + "0b1010", # binary prefix + ]) + def test_non_prefixed_forms_rejected(self, arg): + with pytest.raises(ArgumentTypeError): + systemidtype(arg) + + @pytest.mark.parametrize("bad", [ + "0x", # prefix with no digit + "0xGG", # invalid hex digit + "abc", # not hex + "0x 82", # embedded whitespace + " 0x82", # leading whitespace + "", # empty + " ", # whitespace only + "0x" + "F" * 10000, # very long + ]) + def test_invalid_format_rejected(self, bad): + with pytest.raises(ArgumentTypeError): + systemidtype(bad) + + def test_none_rejected(self): + with pytest.raises((ArgumentTypeError, TypeError)): + systemidtype(None)