| Message ID | 20260715223226.3371498-2-twoerner@gmail.com |
|---|---|
| State | New |
| Headers | show |
| Series | ksparser: four argparse-type fixes plus unit coverage | expand |
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':
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 <twoerner@gmail.com> --- src/wic/ksparser.py | 2 ++ 1 file changed, 2 insertions(+)