@@ -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)
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 <twoerner@gmail.com> --- src/wic/ksparser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)