From b13899c63dbf919822d3e2c16bf03ee2a2f8059e Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 22 Oct 2024 21:37:51 +0000 Subject: [PATCH] make `--u2sz` more intuitive previously, it only accepted the 3-tuple `min,default,max` if given a single integer (or any other unexpected value), the up2k js would enter an infinite loop, eat all the ram and crash the browser (nice) fix this by accepting a single integer (for example 96) and translating it to `1,96,96` --- copyparty/svchub.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index a804b568..518f1686 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -817,6 +817,24 @@ class SvcHub(object): if len(al.tcolor) == 3: # fc5 => ffcc55 al.tcolor = "".join([x * 2 for x in al.tcolor]) + zs = al.u2sz + zsl = zs.split(",") + if len(zsl) not in (1, 3): + t = "invalid --u2sz; must be either one number, or a comma-separated list of three numbers (min,default,max)" + raise Exception(t) + if len(zsl) < 3: + zsl = ["1", zs, zs] + zi2 = 1 + for zs in zsl: + zi = int(zs) + # arbitrary constraint (anything above 2 GiB is probably unintended) + if zi < 1 or zi > 2047: + raise Exception("invalid --u2sz; minimum is 1, max is 2047") + if zi < zi2: + raise Exception("invalid --u2sz; values must be equal or ascending") + zi2 = zi + al.u2sz = ",".join(zsl) + return True def _ipa2re(self, txt) -> Optional[re.Pattern]: