[wic][PATCH 1/5] ksparser: reject negative sizes in sizetype()
Trevor Woerner <[email protected]> Wed, 15 Jul 2026 18:32:22 -0400
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <[email protected]> |
sizetype() splits "<num>[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 <[email protected]> --- 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': -- 2.50.0.173.g8b6f19ccfc3a