diff mbox series

[wic,3/5] ksparser: reject non-finite overhead factors

Message ID 20260715223226.3371498-4-twoerner@gmail.com
State New
Headers show
Series ksparser: four argparse-type fixes plus unit coverage | expand

Commit Message

Trevor Woerner July 15, 2026, 10:32 p.m. UTC
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 <twoerner@gmail.com>
---
 src/wic/ksparser.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

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