{"record":{"id":"692203888f74d2e7","repo":"Comfy-Org/ComfyUI","slug":"exponent-exp-exceeds-maximum-allowed-max-expon","errorCode":null,"errorMessage":"Exponent {exp} exceeds maximum allowed ({MAX_EXPONENT})","messagePattern":"Exponent (.+?) exceeds maximum allowed \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"comfy_extras/nodes_math.py","lineNumber":34,"sourceCode":"\nMAX_EXPONENT = 4000\n\n\ndef _variadic_sum(*args):\n    \"\"\"Support both sum(values) and sum(a, b, c).\"\"\"\n    if len(args) == 1 and hasattr(args[0], \"__iter__\"):\n        return sum(args[0])\n    return sum(args)\n\n\ndef _safe_pow(base, exp):\n    \"\"\"Wrap pow() with an exponent cap to prevent DoS via huge exponents.\n\n    The ** operator is already guarded by simpleeval's safe_power, but\n    pow() as a callable bypasses that guard.\n    \"\"\"\n    if abs(exp) > MAX_EXPONENT:\n        raise ValueError(f\"Exponent {exp} exceeds maximum allowed ({MAX_EXPONENT})\")\n    return pow(base, exp)\n\n\nMATH_FUNCTIONS = {\n    \"sum\": _variadic_sum,\n    \"min\": min,\n    \"max\": max,\n    \"abs\": abs,\n    \"round\": round,\n    \"pow\": _safe_pow,\n    \"sqrt\": math.sqrt,\n    \"ceil\": math.ceil,\n    \"floor\": math.floor,\n    \"log\": math.log,\n    \"log2\": math.log2,\n    \"log10\": math.log10,\n    \"sin\": math.sin,\n    \"cos\": math.cos,","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_math.py#L16-L52","documentation":"Raised by the _safe_pow wrapper exposed as pow() in the math-expression node's function table. simpleeval's own safe_power already caps the ** operator; pow() as a callable would bypass that guard, so this wrapper rejects any exponent with absolute value over MAX_EXPONENT (4000) to prevent multi-minute hangs / DoS from astronomical exponents.","triggerScenarios":"Writing pow(x, 10000) or pow(x, 10**9) in the expression string; computing the exponent dynamically (pow(2, values[0]*2000)) so it exceeds 4000 at runtime; negative huge exponents like pow(2, -99999).","commonSituations":"Iterative-growth formulas, factorial approximations, or user typos (extra zero in the exponent) in the Math Expression node.","solutions":["Restructure the math: use exp(n * log(x)) style formulations, or square repeatedly with bounded loop counts.","Check whether such a huge exponent is really intended — pow(2, 4001) already overflows float64 to inf.","Cap dynamic exponents before use: min(abs(e), 4000) or clamp values upstream."],"exampleFix":"// before\npow(values[0], 99999)\n\n// after\nexp(99999 * log(values[0]))  // or reduce the exponent to a sane magnitude","handlingStrategy":"validation","validationCode":"MAX_EXPONENT = 4000\nexp = int(exp) if isinstance(exp, (int, float)) else len(exp)\nassert abs(exp) <= MAX_EXPONENT, f\"exponent {exp} exceeds the {MAX_EXPONENT} cap; restructure the math (exp/log) instead\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exponents well under 4000 — float64 overflows near 10^308 anyway.","Compute extreme powers via exp(n * log(x)) instead of pow().","Clamp dynamically computed exponents before use."],"tags":["math","expression","dos-guard","pow","limits"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}